Giri Dharan Giri Dharan - 1 year ago 106 Question

Alert not working in UpdatePanel VB.Net

Here is what I have tried.

ASPX File:

<asp:UpdatePanel ID="UpdatePanel1" runat="server">

<asp:Button OnClick="btnOK1_Click" ID="btnOK1" runat="server" Text="Save" />



Protected Sub btnOK1_Click(sender As Object, e As EventArgs)
Dim alertMsg As String
Dim alertScript As String
alertMsg = String.Format("You Selected {0}", "My Message")
alertScript = String.Format("<script type= text/javascript>alert('{0}');</script>", alertMsg)
ClientScript.RegisterStartupScript(Me.[GetType](), "Alert", alertScript)
End Sub

I tried to get an alert box with a message when clicked a button (Save) from backend. I tried with the solutions from the StackOverflow. But, the codes does not work for me to get an javascript alert box. The event triggers fine and runs through the code. Anyone help me with this?

Answer Source

The problem seems to lie with the fact that you are using ClientScript rather than ScriptManager.

ClientScript is used for Synchronous postbacks, whereas ScriptManager for Asycronous.

See this question for more details.