65.9K
CodeProject is changing. Read more.
Home

ModalPopupExtender from Server Side Code

starIconstarIconstarIconstarIcon
emptyStarIcon
starIcon

4.92/5 (17 votes)

Jun 22, 2011

CPOL
viewsIcon

99483

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
<!-- 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.