Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dynamic js file at runtime 1

Status
Not open for further replies.

TallOne

Programmer
May 14, 2004
164
US
Hi all,

At the bottom is the head section of my aspx page. I want to set the src prop of the script at run time.

src="Scripts/iphonenavIE.js"
or
src="Scripts/iphonenavSafari.js"

If I add an ID and RUNAT props I get tons of unrelated errors on build and intellisense doesn't recognize the object. I'm using Web Application and cannot access the designer pages. :(

Can anyone tell me what I'm missing here???

I've tried
Code:
IF .... Then
ClientScript.RegisterClientScriptBlock(Me.GetType(), "Navigation", "<script language='javascript' src='Scripts/iphonenavIE.js'/>")
Else
ClientScript.RegisterClientScriptBlock(Me.GetType(), "Navigation", "<script language='javascript' src='Scripts/iphonenavIE.js'/>")
End If


BTW it works with links.... but not scripts! :(
Code:
<link id="linkStyle" runat="server" rel="stylesheet" type="text/css" />
CODE BEHIND
Code:
linkStyle.Attributes.Add("href", clsUtility.xReturnStyle())



Code:
<head>
<title>iPhone Navigation</title>
<link id="linkStyle" runat="server" rel="stylesheet" type="text/css" />

<meta name="viewport" content="width=320; initial-scale=1.0; maximum-scale=1.0; user-scalable=0;"/>
<style type="text/css" media="screen">@import "Style/iPhoneNav/iphonenav.css";</style>
<script type="text/javascript" src="Scripts/iphonenavIE.js"></script>
</head>
 
when adding js scipts to a page you cannot use self closing tags.
Code:
<script language="javascript" type="text/js" src="../file.js></script>
Code:
<script language="javascript" type="text/js" src="../file.js />

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
Thanks ca8msm. I ended up combining js files to keep my logic in one place. For learning purposes and in the event I need to use this technique in the future, what's the correct usage? Are asp:controls allowed in the head tag?

Code:
<head>
   <asp:Literal id="Literal1" runat="server"></asp:Literal>
</head>


Code:
'Page Load & Not Postback
Literal1.Text = "<script language='javascript' src='Scripts/iphonenavIE.js'/>"
 
Make your <head> tag runat="server"
Code:
    Public Shared Sub AddJSToPage(ByRef header As HtmlControls.HtmlHead, ByVal FileName As String)
                Dim IncludeJS As New HtmlGenericControl("script")
                IncludeJS.Attributes.Add("type", "text/javascript")
                IncludeJS.Attributes.Add("src", "Your Application Path Here"+ "js path and filename here")
                header.Controls.Add(IncludeJS)
    End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top