user228058
user228058

Reputation: 475

conditional javascript in .ascx

I have a javascript src that i need to add to some of the pages in a site.

for example <script type="text/javascript" src="http:abcxyz.com/zzz"></script>

I want to add this conditionally on a .ascx page - if the Request.ServerVariables["SCRIPT_NAME"] ends with certain criteria.

The ascx language is vb, and there is no code behind.

Thanks

Upvotes: 1

Views: 2443

Answers (2)

Joel Etherton
Joel Etherton

Reputation: 37533

If you make it so the tag is runat=server, you should be able to conditionally add the code as script:

<head runat="server">

  <% If Request.ServerVariables("SCRIPT_NAME") = "value" Then %>
    <script type="text/javascript" src="whatever.js"></script>
  <% Else %>
    <script type="text/javascript" src="whatever_else.js"></script>
  <% End If %>

</head>

Upvotes: 1

James Gaunt
James Gaunt

Reputation: 14783

No code behind, but still code in front right?

This will probably do it...

<%= If(Request.ServerVariables("SCRIPT_NAME").EndsWith("<criteria>"), "<script type='text/javascript' src='http:abcxyz.com/zzz'></script>", "")%>

Upvotes: 0

Related Questions