[asp.net] RegisterStartupScript from code behind not working when Update Panel is used

I have created a radiobutton list followed by one button. I can select one of the item from the radiobutton list and then click the button to execute something. And I want the page to pop up a window if the button is clicked without selecting any of the options from the radiobutton list. My codebehide is like this:

    protected void ButtonPP_Click(object sender, EventArgs e)     {         if (radioBtnPP.SelectedIndex < 0)         {             String csname1 = "PopupScript";             Type cstype = this.GetType();              // Get a ClientScriptManager reference from the Page class.             ClientScriptManager cs = Page.ClientScript;              // Check to see if the startup script is already registered.             if (!cs.IsStartupScriptRegistered(cstype, csname1))             {                 StringBuilder cstext1 = new StringBuilder();                 cstext1.Append("<script type=text/javascript> alert('Please Select Criteria!') </");                 cstext1.Append("script>");                  cs.RegisterStartupScript(cstype, csname1, cstext1.ToString());             }         }    } 

and my html part is:

    <asp:RadioButtonList class ="radioBtn" ID="radioBtnACO" runat="server">            <asp:ListItem Text="All Dim" />            <asp:ListItem Text="Select Dim" />     </asp:RadioButtonList>     <asp:Button id ="ButtonPP" class ="buttonRight" runat="server" Text="Run PP" OnClick="ButtonPP_Click" /> 

This works fine. However, now I don't want to refresh the whole page when i click the button, so I use updatepanel. And I changed my html code to the following:

    <asp:ScriptManager ID="ScriptManager1" runat="server">     </asp:ScriptManager>     <asp:UpdatePanel ID="ControlUpdatePanel" runat="server" Visible="True">         <ContentTemplate>              <asp:RadioButtonList class ="radioBtn" ID="radioBtnACO" runat="server">                <asp:ListItem Text="All Dim" />                <asp:ListItem Text="Select Dim" />            </asp:RadioButtonList>            <asp:Button id ="ButtonPP" class ="buttonRight" runat="server" Text="Run PP" OnClick="ButtonPP_Click" />         </ContentTemplate>    </asp:UpdatePanel>   

But now my code doesn't work anymore... If I don't select any option from the radiobutton list and just click the button, no window would pop up :( I am sure my codebehind is still executed but seems like it just doesn't passed to my .aspx page...

Anyone please help me out? I don't know what to do now... Millions of thanks!

This question is related to asp.net updatepanel popupwindow buttonclick

The answer is


You need to use ScriptManager.RegisterStartupScript for Ajax.

protected void ButtonPP_Click(object sender, EventArgs e) {     if (radioBtnACO.SelectedIndex < 0)     {         string csname1 = "PopupScript";          var cstext1 = new StringBuilder();         cstext1.Append("alert('Please Select Criteria!')");          ScriptManager.RegisterStartupScript(this, GetType(), csname1,             cstext1.ToString(), true);     } } 

Examples related to asp.net

RegisterStartupScript from code behind not working when Update Panel is used You must add a reference to assembly 'netstandard, Version=2.0.0.0 No authenticationScheme was specified, and there was no DefaultChallengeScheme found with default authentification and custom authorization How to use log4net in Asp.net core 2.0 Visual Studio 2017 error: Unable to start program, An operation is not legal in the current state How to create roles in ASP.NET Core and assign them to users? How to handle Uncaught (in promise) DOMException: The play() request was interrupted by a call to pause() ASP.NET Core Web API Authentication Could not load file or assembly 'CrystalDecisions.ReportAppServer.CommLayer, Version=13.0.2000.0 WebForms UnobtrusiveValidationMode requires a ScriptResourceMapping for jquery

Examples related to updatepanel

RegisterStartupScript from code behind not working when Update Panel is used How do I use updatePanel in asp.net without refreshing all page? ASP.NET Display "Loading..." message while update panel is updating ASP.NET postback with JavaScript Can't get ScriptManager.RegisterStartupScript in WebControl nested in UpdatePanel to work ModalPopupExtender OK Button click event not firing? RegisterStartupScript from code behind not working when Update Panel is used how to make window.open pop up Modal? Add a UIView above all, even the navigation bar How to handle Pop-up in Selenium WebDriver using Java jQuery function to open link in new window Popup window in PHP? How to create a popup window (PopupWindow) in Android Blur or dim background when Android PopupWindow active

Examples related to buttonclick

RegisterStartupScript from code behind not working when Update Panel is used How to press/click the button using Selenium if the button does not have the Id? How to launch another aspx web page upon button click? How to make a button redirect to another page using jQuery or just Javascript