Results 1 to 9 of 9

Thread: How come RegisterStartupScript doesn't work if there is codes on the next line?

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Feb 2006
    Posts
    101

    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)

  2. #2
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: How come RegisterStartupScript doesn't work if there is codes on the next line?

    VB Code:
    1. Dim strCreateFile As String
    2. strCreateFile = "<script language='javascript'>"
    3. strCreateFile += "function myfxn(){ var fso = new ActiveXObject('Scripting.FileSystemObject');"
    4. strCreateFile += "var textFile = fso.CreateTextFile('C:\\CUTTER.vts');"
    5. strCreateFile += "var text = 'Version = " + txtVersion.Text + "';"
    6. strCreateFile += "textFile.WriteLine(text);"
    7. strCreateFile += "textFile.Close();}"
    8. strCreateFile += "</script>"
    9.  
    10. Page.RegisterClientScriptBlock("myfxn",strCreateFile)
    11. Page.RegisterStartupScript("myfxncall","<script language=javascript>myfxn();</script>")

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Feb 2006
    Posts
    101

    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")

  4. #4
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    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?

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Feb 2006
    Posts
    101

    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?

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Feb 2006
    Posts
    101

    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.

  7. #7
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    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.

  8. #8

    Thread Starter
    Lively Member
    Join Date
    Feb 2006
    Posts
    101

    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..

  9. #9
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    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?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width