kanden
asked on
ASP.net and Javascript
I have a huge Javascript file .js, I need to add information from a Database to it in certain places. I have tried response.write("file.js")
Is there a way to do this?
Is there a way to do this?
ASKER
Sorry, I am being to vague.
I need to add information inside the Javascript file dynamiclly with asp.net
I need to add information inside the Javascript file dynamiclly with asp.net
Dim reader As StreamReader
reader = New StreamReader(Page.Server.M apPath("Yo urFile.js" ))
Dim script As String = reader.ReadToEnd()
Page.RegisterClientScriptB lock("Your Script", script)
reader = New StreamReader(Page.Server.M
Dim script As String = reader.ReadToEnd()
Page.RegisterClientScriptB
Otherwise... you need to create the javascript on the fly (basically using a StringBuilder). And then register the script... like this:
Dim script As StringBuilder = New StringBuilder(4096)
Dim CRLF As String = ControlChars.CrLf
With script
.Append("<script lang=JScript> " & CRLF)
.Append("function IsValidDateTime(source, args) " & CRLF)
' Lots of javascript removed
.Append("</script> ")
End With
Page.RegisterClientScriptB lock("Your Script", script.tostring)
Dim script As StringBuilder = New StringBuilder(4096)
Dim CRLF As String = ControlChars.CrLf
With script
.Append("<script lang=JScript> " & CRLF)
.Append("function IsValidDateTime(source, args) " & CRLF)
' Lots of javascript removed
.Append("</script> ")
End With
Page.RegisterClientScriptB
ASKER
Ok,
I like option 1 the best. If I get it the reader is reading the file to the end then adding my script to the end of the file. Is there a way to specify a point in the file to start writing and will this parse before the:
<script language="javascript" src="file.js" type="text/javascript"></s cript>
??
I like option 1 the best. If I get it the reader is reading the file to the end then adding my script to the end of the file. Is there a way to specify a point in the file to start writing and will this parse before the:
<script language="javascript" src="file.js" type="text/javascript"></s
??
The RegisterScriptClientBlock adds a script block to the output, if it has not already been added. It checs for the existence of a block called "YourScript".
So... you don't need to specify a point to write to, and it parses just fine.
So... you don't need to specify a point to write to, and it parses just fine.
ASKER
The problem is that I need to add lines to certain functions within the file.
am I not getting it?
am I not getting it?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
you sound like your trying to do things a bit backwards here..
what and how much are you trying to write to the javascript...
if most of the javascript is generic and used enough times you put as much into the .js file and use what others have said
<script language="javascript" src="file.js" type="text/javascript"></s cript>
then in the building of the page you use the registerclientscript blocks to add the extra stuff you need.. It's the power of functions that you souldn't really need to add lines to a js file..
Like I said before.. it might help to see an example of what your trying to add.
CooPzZ
what and how much are you trying to write to the javascript...
if most of the javascript is generic and used enough times you put as much into the .js file and use what others have said
<script language="javascript" src="file.js" type="text/javascript"></s
then in the building of the page you use the registerclientscript blocks to add the extra stuff you need.. It's the power of functions that you souldn't really need to add lines to a js file..
Like I said before.. it might help to see an example of what your trying to add.
CooPzZ
<script language="javascript" src="file.js" type="text/javascript"></s