Search code examples
c#asp.netasp.net-ajaxupdatepanel

Showing JavaScript Alert Message inside UpdatePanel in ASP.Net Issue


Hi i found this below solution with ScriptManager

string message = "alert('Hello!')";
ScriptManager.RegisterClientScriptBlock((sender as Control), this.GetType(), "alert", message, true);

the issue is i am using ToolkitScriptManager

How can make the code work with ToolkitScriptManager

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>
<cc1:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
</cc1:ToolkitScriptManager>

Solution

  • It will work with ToolScriptManager also(only if you have PostBack trigger)

     Response.Write(@"<script Language=""javascript"" >alert('"+Your Message here+"')</script>");
    

    Code below works with both ToolScriptManager and ScriptManager(For Async Trigger also)

     String TransferPage;
     TransferPage = "<script>alert('Your Message')</script>";
     ScriptManager.RegisterStartupScript(Page, Page.GetType(), "temp", TransferPage, false);