Click here to Skip to main content
Click here to Skip to main content

Tagged as

Go to top

ModalPopupExtender from Server Side Code

, 25 Jun 2011
Rate this:
Please Sign up or sign in to vote.
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.

License

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

Share

About the Author

Frank Kerrigan
Software Developer (Senior)
United Kingdom United Kingdom
Frank Kerrigan
 
Currently developing Insurance systems with SQL Server, ASP.NET, C#, ADO for a company in Glasgow Scotland. Very keen on OOP and NUNIT testing. Been in IT forever (20 years) in mix of development and supporting applications / servers. Worked for companies big and small and enjoyed both.
 
Developed in (newest first) : C#, Progress 4GL, ASP.NET, SQL TSQL, HTML, VB.NET, ASP, VB, VBscript, JavaScript, Oracle PSQL, perl, Access v1-2000, sybase/informi, Pic Controllers, 6502 (ask your dad).
 
Msc .Net Development Evenings www.gcu.ac.uk
MCAD Passed
MCP C# ASP.NET Web Applications
MCP SQL Server 2000
HND Computing
OND / HNC Electrical Engineering,
Follow on   Twitter

Comments and Discussions

 
QuestionGood Article PinmemberSraven Kande22-Jul-14 7:54 
Questionquery Pinmembervidyaraj147-Nov-13 1:32 
QuestionModalPopup show call from code behind page Pinmemberswethavor17-Feb-13 5:48 
GeneralMy vote of 5 PinmemberBilal Fazlani22-May-12 21:27 
Generalvery good trick! PinmemberBilal Fazlani22-May-12 21:26 
GeneralRe: I agree, Frank! My best, Alex PinmemberDrABELL27-Jun-11 4:14 
GeneralHi Frank, Thanks for sharing this very practical solution. I... PinmemberDrABELL23-Jun-11 2:57 
GeneralRe: Cheers for the feedback, I'll leave my tip as or it or it wi... PinmemberFrank Kerrigan27-Jun-11 3:38 
GeneralReason for my vote of 5 Very practical solution! PinmemberDrABELL23-Jun-11 2:52 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web01 | 2.8.140921.1 | Last Updated 25 Jun 2011
Article Copyright 2011 by Frank Kerrigan
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid