How come RegisterStartupScript doesn't work if there is codes on the next line?
I have implement a javascript codes into the sub procedure and execute it by using the RegisterStartupScript. One thing I find out about using the RegisterStartupScript, is that if there is codes after it, it doesn't work. But if I erased all of the codes after it, it will work. How come?
Dim strCreateFile As String
strCreateFile = "<script language='javascript'>"
strCreateFile += "{ var fso = new ActiveXObject('Scripting.FileSystemObject');"
strCreateFile += "var textFile = fso.CreateTextFile('C:\\CUTTER.vts');"
strCreateFile += "var text = 'Version = " + txtVersion.Text + "';"
strCreateFile += "textFile.WriteLine(text);"
strCreateFile += "textFile.Close();}"
strCreateFile += "</script>"
RegisterStartupScript("Startup", strCreateFile)
Re: How come RegisterStartupScript doesn't work if there is codes on the next line?
VB Code:
Dim strCreateFile As String
strCreateFile = "<script language='javascript'>"
strCreateFile += "function myfxn(){ var fso = new ActiveXObject('Scripting.FileSystemObject');"
strCreateFile += "var textFile = fso.CreateTextFile('C:\\CUTTER.vts');"
strCreateFile += "var text = 'Version = " + txtVersion.Text + "';"
strCreateFile += "textFile.WriteLine(text);"
strCreateFile += "textFile.Close();}"
strCreateFile += "</script>"
Page.RegisterClientScriptBlock("myfxn",strCreateFile)
Page.RegisterStartupScript("myfxncall","<script language=javascript>myfxn();</script>")
Re: How come RegisterStartupScript doesn't work if there is codes on the next line?
It didn't work. The code afterwards is: Response.Redirect("C:\myfile.txt")
Re: How come RegisterStartupScript doesn't work if there is codes on the next line?
Response.Redirect stops page execution and redirects the file to c:\myfile.txt. It's not supposed to work. Nothing is.
Why are you redirecting afterwards? Any reason?
Re: How come RegisterStartupScript doesn't work if there is codes on the next line?
To launch that created file. Within the file, it has Username, password, port number, etc. Is there a better way than using Response.Redirect?
Re: How come RegisterStartupScript doesn't work if there is codes on the next line?
What is the purpose of the RegisterClientScriptBlock anyways? The codes work with just the RegisterStartupScript.
Re: How come RegisterStartupScript doesn't work if there is codes on the next line?
Startup script is to be called when the page loads.
Client script block is to register your javascript functions. Functions, not calls to functions.
Try using javascript's document.location.href to navigate to the created file.
Re: How come RegisterStartupScript doesn't work if there is codes on the next line?
document.location.href works on the local computer with the ASP.NET page on the same computer as the hosting. But not on the server and accessing from a local computer.
My boss just went ahead and order a product called, Intralaunch, which use to launch file and it works but it just cost money.
Still want to know about launching a file through coding though. If it is ever possible..
Re: How come RegisterStartupScript doesn't work if there is codes on the next line?
What happens instead?
Does the file you created actually GET created on the client's machine? Can you verify this?