ASP.NET WebForms Modal Popup

I want to know what is the best way to show modal popups in ASP.NET WebForms application. I need to display a modal window with 2 buttons (OK / Cancel) and click the button in my code. What should I use to implement it - ModalPopupExtender from AjaxControlToolkit, bootstrap modal popup or jQuery UI? I'm new to ASP.NET WebForms, so a source code example or tutorial would be helpful. Thank you!


source to share

1 answer

Hey check this code using modalpopupextender

. But first, you need to install AjaxControlToolKit from the Nuget Package Manager and add it as an assembly reference at the top of the .aspx page as a directive like:

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajaxToolkit" %>


Then here is the code from modalpopupextender


     <asp:Button ID="btnOpenPopUp" runat="server" text="Open PopUp" />
     <asp:Label ID="lblHidden" runat="server" Text=""></asp:Label>
        <ajaxToolkit:ModalPopupExtender ID="mpePopUp" runat="server" TargetControlID="lblHidden" PopupControlID="divPopUp" BackgroundCssClass="modalBackground"></ajaxToolkit:ModalPopupExtender>

<div id="divPopUp" class="pnlBackGround">
     <div id="Header" class="header" >MyHeader</div>
     <div id="main" class="main">Main PopUp </div>
     <div id="buttons">
          <div id="DivbtnOK" class="buttonOK"><asp:Button id="btnOk" runat="server" text="Ok" /></div>
          <div id="Divbtncancel" class="buttonOK"><asp:Button id="btnCancel" runat="server" text="Cancel" /></div>


then from the Code on On Click event of the Open PopUp button:

protected void btnOpenPopUp_Click(object sender, ImageClickEventArgs e)


then click OK:

protected void btnOk_Click(object sender, ImageClickEventArgs e) {
    //Do Work

    mpePopUp.Hide(); }


Click the "Cancel" button:

protected void btnCancel_Click(object sender, ImageClickEventArgs e)
    //Do Work



Council. If you don't have ajax toolkit, you can install it using Nuget.



All Articles