Click here to Skip to main content
15,867,750 members
Articles / Web Development / ASP.NET
Tip/Trick

ModalPopupExtender from Server Side Code

Rate me:
Please Sign up or sign in to vote.
4.92/5 (17 votes)
25 Jun 2011CPOL 96.4K   1   13
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)


Written By
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,

Comments and Discussions

 
GeneralMy vote of 5 Pin
MrCodeIt11-Aug-15 9:14
MrCodeIt11-Aug-15 9:14 
QuestionAwesome solutions Pin
MrCodeIt11-Aug-15 9:21
MrCodeIt11-Aug-15 9:21 
QuestionVery interesting! Pin
robertd9039-Dec-14 15:48
robertd9039-Dec-14 15:48 
QuestionGood Article Pin
Sraven Kande22-Jul-14 7:54
Sraven Kande22-Jul-14 7:54 
Questionquery Pin
vidyaraj147-Nov-13 1:32
vidyaraj147-Nov-13 1:32 
QuestionModalPopup show call from code behind page Pin
swethavor17-Feb-13 5:48
swethavor17-Feb-13 5:48 
GeneralMy vote of 5 Pin
Bilal Fazlani22-May-12 21:27
Bilal Fazlani22-May-12 21:27 
Generalvery good trick! Pin
Bilal Fazlani22-May-12 21:26
Bilal Fazlani22-May-12 21:26 
GeneralRe: I agree, Frank! My best, Alex Pin
DrABELL27-Jun-11 4:14
DrABELL27-Jun-11 4:14 
GeneralHi Frank, Thanks for sharing this very practical solution. I... Pin
DrABELL23-Jun-11 2:57
DrABELL23-Jun-11 2:57 
GeneralRe: Cheers for the feedback, I'll leave my tip as or it or it wi... Pin
Frank Kerrigan27-Jun-11 3:38
Frank Kerrigan27-Jun-11 3:38 
GeneralReason for my vote of 5 Very practical solution! Pin
DrABELL23-Jun-11 2:52
DrABELL23-Jun-11 2:52 
Reason for my vote of 5
Very practical solution!

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

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