Geeks With Blogs
Bunch's Blog One day I'll have a catchy subtitle, one day

Something that stumped me a few years ago was trying to code a Javascript window (i.e. alert, confirm) from the code behind. I’ve listed some code below on how I did it in VS2005 using VB. For VS2003 the idea is the same but use Page in place of ClientScript and remove the GetType(String) parameter.

One thing you do lose when doing it this way is any execution control that goes along with let’s say a confirm window. The window will appear but the rest of the code in the code behind sub or void will run without waiting for a confirmation from the confirm window.

Dim strMessage As String = “Test Message”

Dim strScript As String = "<script language=JavaScript>"

        strScript += "alert(""" & strMessage & """);"

         strScript += "</script>"

         If (Not ClientScript.IsStartupScriptRegistered("clientScript")) Then

              ClientScript.RegisterStartupScript(GetType(String), "clientScript", strScript)

         End If

Technorati Tags: ,
Posted on Thursday, May 15, 2008 9:53 AM ASP.Net | Back to top

Comments on this post: Javascipt Window From Code Behind

No comments posted yet.
Your comment:
 (will show your gravatar)

Copyright © Bunch | Powered by: