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

ModalPopupExtender from Server Side Code

By , 25 Jun 2011
 
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)

About the Author

Frank Kerrigan
Software Developer (Senior)
United Kingdom United Kingdom
Member
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,

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
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 
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   

Permalink | Advertise | Privacy | Mobile
Web03 | 2.6.130516.1 | Last Updated 25 Jun 2011
Article Copyright 2011 by Frank Kerrigan
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid