Hi friends..

I am trying to display message box using server-side code. I have written code in buttons click event and Page Load Event. It is as follows :

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        TextBox1.Text = "I Enjoy ASP.NET"

        Dim myscript As String = "alert(document.getElementById('TextBox1').value);"
        Page.ClientScript.RegisterStartupScript(Me.GetType(), "myscript", myscript, True)
    End Sub

    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim strMessage As String
        strMessage = "Hi, You clicked ClickMe button"
        Dim strScript As String = "<script language=JavaScript>"
        strScript += "alert('" & strMessage & "');"
        strScript += "</script>"

        If (Not ClientScript.IsStartupScriptRegistered("clientScript")) Then
            ClientScript.RegisterClientScriptBlock(Me.GetType(), "clientScript", strScript)
        End If
    End Sub

If button is not in UPDATE PANEL, then both alert are displayed normally (i.e. during Page Load and Button Click)

But when I put the button inside UPDATE PANEL , alert dosn't work in Button Click. Here only Page_Load alert is displayed
In case of UPDATE PANEL is also tried
but in vain..!!!
Any ideas??

/forums/clientscriptManager class does not work inside UpdatePanel. Use the ScriptManager class instead.

try the folllowing code it will dafinately work

ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), Guid.NewGuid().ToString(), "alert('" "')", true);

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.19 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.