Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / web / ASP.NET

ModalPopupExtender from Server Side Code

4.92/5 (17 votes)
25 Jun 2011CPOL 99.3K  
Enabling ModalPopupExtender from ServerSide Code in the Ajax Control Kit
Getting the ModalPopupExtender to work from Server Side Code is quite simple once you know how. The control can be triggered via code with the Show method, but you need a dummy client control for the TargetControlID in the ModalPopupExtender.

I've used an ASP.NET HiddenField which will render correctly without using style sheet magic to hide it from the form.

The complete code is shown below:

HTML CODE

XML
<!-- Hidden Field -->
<asp:HiddenField ID="hidForModel" runat="server" />

<asp:ModalPopupExtender
ID="WarningModal"
TargetControlID="hidForModel"
runat="server"
CancelControlID="btnWarning"
DropShadow="true"
PopupControlID="pnlIssues" >
</asp:ModalPopupExtender>

<!-- Panel -->
<asp:Panel ID="pnlIssues" runat="server"  
BorderColor="Black" BorderStyle="Outset"  
BorderWidth="2" BackColor="Wheat" Width="400px"  Height="106px">
   <center>
       <h2 class="style2">
           Information</h2>
       <p>

         <h3> <asp:Label ID="lblWarning" 
runat="server"> </asp:Label></h3>
       </p>

 <!-- Label in the Panel to turn off the popup -->
 <asp:ImageButton ID="btnWarning" runat="server"
                ImageUrl="~/images/buttons/update.png" />
</center>

</asp:Panel>



C# Code

WarningModal.Show();
lblWarning.Text = "This is a popup warning";

Enjoy and remember to vote.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)