Skip to content Skip to sidebar Skip to footer

Asp.net Server Side Show Js Alert Box, Doesn't Work When Using Partial Post Back

I have put the following method in my master page. It works when I call it on a full post back, but when I call it from a updatePanel's asyncPostBack no alert is shown. public

Solution 1:

You have to register the script with the ScriptManager:

ScriptManager.RegisterStartupScript(this, typeof(Page), UniqueID, "alert('hi')", true);

Here is some more information:

Inline Script inside an ASP.NET AJAX UpdatePanel

Solution 2:

You should use ScriptManager.RegisterStartupScript instead:

<%@ Page Language="C#" AutoEventWireup="true" %>
<scriptrunat="server"type="text/C#">
protected voidBtnClick(object sender, EventArgs e)
{
    string alertScript = "alert('Hello');";
    ScriptManager.RegisterStartupScript(this, GetType(), "Key", alertScript, true);
}
</script><!DOCTYPE htmlPUBLIC"-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><htmlxmlns="http://www.w3.org/1999/xhtml" ><headrunat="server"><title></title></head><body><formid="form1"runat="server"><asp:ScriptManagerID="sm"runat="server" /><asp:UpdatePanelID="up"runat="server"><ContentTemplate></ContentTemplate><Triggers><asp:AsyncPostBackTriggerControlID="btn"EventName="Click" /></Triggers></asp:UpdatePanel><asp:LinkButtonID="btn"runat="server"OnClick="BtnClick"Text="Test" /></form></body></html>

Post a Comment for "Asp.net Server Side Show Js Alert Box, Doesn't Work When Using Partial Post Back"