C# .NET - How can i call a popupextender in code

Asked By balaji mogadali
04-Aug-11 01:19 AM
hi frds

how can i call a popupextender  in c# assiging control at runtime
  K S replied to balaji mogadali
04-Aug-11 01:23 AM
Refer this:

http://www.ezzylearning.com/tutorial.aspx?tid=2761931

http://www.asp.net/ajax/ajaxcontroltoolkit/Samples/PopupControl/PopupControl.aspx
  James H replied to balaji mogadali
04-Aug-11 01:24 AM

Working with Modal Popup extender control.

This blog discusses about the ASP.NET AJAX ModalPopupExtender control. In this blog we will see how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, showing/displaying/calling the modal popup from a hyper link control within the gridview control and finally some important javascript methods of the ASP.NET AJAX ModalPopupExtender control. So first lets see how to use the ModalPopupExtender control.

How to use the ASP.NET AJAX ModalPopupExtender control?

Drag and drop a ASP.NET button/LinkButton/ImageButton or any control to an aspx page. To add a ModalPopupExtender control, drag and drop the control from the toolbox or Select the any of the ASP.NET controls like (button/LinkButton/ImageButton or any other control) and click the button with a greater than symbol as shown below.

http://lh5.ggpht.com/_QY7fSC4VqiA/Sk3HrYCaMMI/AAAAAAAAC40/baIjKjgb8UI/s1600-h/image17.png

When you click the arrow you will get a menu with an “Add Extender” option as shown below.

http://lh6.ggpht.com/_QY7fSC4VqiA/Sk3Ht1n5_iI/AAAAAAAAC48/PWpV3ouvkh0/s1600-h/image16.png

Click the “Add Extender” menu option and select “ModalPopupExtender” from “Extender Wizard” popup. Once you have added the ModalPopupExtender control you need an ASP.NET panel control. This is because the ModalPopupExtender control will show the content of the Panel control as a popup. Add ASP.NET Panel control and the content which you want to display as popup into the ASP.NET Panel control. Sample code with all the above requirement is pasted below. Don’t forget to drag and drop the ScriptManager control to the page.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 
<html xmlns="http://www.w3.org/1999/xhtml">
 
<head runat="server">
 
  <title>Modal Popup Demo</title>
 
  <style>
 
  .backgroundColor
 
  {
 
    background-color:Gray;   
 
    filter:alpha(opacity=25);
 
  }
 
  </style>
 
</head>
 
<body>
 
  <form id="form1" runat="server">
 
  <div>
 
    <asp:ScriptManager ID="ScriptManager1" runat="server">
 
    </asp:ScriptManager>     
 
    <asp:Button ID="popupBtn" runat="server" Text="Click to see the modal popup." />
 
    <asp:Panel ID="Panel1" runat="server" Style="display: none; padding:10px; border:1px; border-style:solid;" BackColor="#FF9933" Width="400px">
 
      <h3 style="text-align: center;" id="header">Modal Popup</h3>
 
      <p>This is a Modal Popup extender control. You are seeing this because you have clicked the hyperlink button.</p>
 
      <p style="text-align: center;"><asp:Button ID="closeBtn" runat="server" Text="Close" /></p>     
 
    </asp:Panel>
 
    <cc1:ModalPopupExtender ID="ModalPopupExtender" runat="server"
 
      TargetControlID="popupBtn"
 
      PopupControlID="Panel1"       
 
      OkControlID="closeBtn"
 
      BackgroundCssClass="backgroundColor"
 
      DropShadow="true"
 
      PopupDragHandleControlID="header"/>
 
  </div>
 
  </form>
 
</body>
 
</html>

From the above code one can see I have a ScriptManager, an asp:Button control, an asp:Panel control, some contents inside the panel control and then we have the ModalPopupExtender control. Normally when you attach an ASP.NET panel control to a ModalPopupExtender control it will become invisible in the HTML rendered to the browser and if due to some reason if the panel control is being displayed in the page then just set the "Style" property' “display” attribute to “none” as in the above e.g. Now when you click the button you will see a popup as shown below.

http://lh6.ggpht.com/_QY7fSC4VqiA/Sk3Hv8q91bI/AAAAAAAAC5E/jRVw6idcvn0/s1600-h/image4.png

Now lets see how to configure the ModalPopupExtender control. The configuration is pretty simple, you need to set some properties and and you will have your Modal popup. The properties are as follows

TargetControlID: This property is the one which tells, on click of which control the popup should be displayed. In our e.g. we have given the TargetControlID as our button control. You can assign the ID of any ASP.NET controls like LinkButton, ImageButton, HyperLink, DropDownList, CheckBox, RadioButton etc. Even you can give a label’ id as the TargetControlID.

PopupControlID: The ID of the control to be displayed as a modal popup. In our e.g. we have given ASP.NET panel control’ ID. You can give any ASP.NET control’ ID. If for e.g if you give the ID of a textbox then the textbox alone will be popped up. Its not compulsory that you should provide a ASP.NET panel control.

OkControlID: The ID of the control which should act as an Ok button. Clicking of this control will dismiss the popup.

BackgroundCssClass: The name of the CSS class which needs to be applied to the background of the popup. One thing to note here is that if you don’t provide a CSS class then the modal popup will not function like a modal dialog i.e. One will be able to interact with the controls in the back of the popup control, so its imperative to provide a valid CSS class name value to the BackgroundCssClass property. In the above e.g. we have defined a CSS class called “backgroundColor” in the header section of the aspx page. Please note in the CSS class definition we have applied “filter” property to make the background transparent.

DropShadow: Accepts a boolean value which specifies whether the popup should have shadow. True will give a shadow and false will disable the shadow.

PopupDragHandleControlID: The ID of the control clicking on which the ModalPopupExtender can be dragged. The control should be enclosed in the control specified using PopupControlID i.e. in our case inside the ASP.NET panel control. If a particular control ID is set as the PopupDragHandlerControlID then one can click on that control and drag the ModalPopupExtender control. In the above e.g. we have set the ID of the “h3” control as PopupDragHandleControlID, clicking which the popup can be dragged.

CancelControlID: If you want a button to behave as a Cancel button provide the ID of the button. This button will cancel the popup.

Drag: This property takes a boolean value which when set decides whether the popup control can have the drag feature. A value of true means the popup extender control can be dragged around the screen whereas false will disable the drag.

RepositionMode: This property accepts four values. They are “None”, “RepositionOnWindowResize”, “RepositionOnWindowResizeAndScroll” and “RepositionOnWindowScroll”. The default value is “RepositionOnWindowResizeAndScroll”. Explanation of each values is given below.

RepositionOnWindowResize: Will reposition the popup when the window is resized.

RepositionOnWindowScroll: Will reposition the popup when the scroll bar is moved.

RepositionOnWindowResizeAndScroll: Will reposition the popup when you resize or when you move the scroll bar. Its a combination of both “RepositionOnWindowResize” and “RepositionOnWindowScroll”.

None: The popup will not be tinkered with. It will be shown in its original position irrespective of window resizing or scroll bar being moved.

DynamicServicePath: Link to a webservice/aspx page from where data or content needs to be retrieved and displayed in the popup extender control.

DynamicServiceMethod: The method name from which content needs to be retrieved. The method can be a webservice method or a method in your code behind file of your aspx file. If you leave the “DynamicServicePath” empty and provide DynamicServiceMethod name then the system will try to ping the same page’ and try to find a method. We will see an e.g. with web service shortly.

DynamicContextKey: The string value which will be passed as the parameter to the method specified in DynamicServiceMethod. One thing to note here is that the parameter should be named contextKey in the webservice/code behind.

X: The X coordinates for the popup control.

Y: The Y coordinates for the popup control.

http://www.eggheadcafe.com/forumpostsubmission.aspx?topicid=2&forumpostid=10341423

  Ravi S replied to balaji mogadali
04-Aug-11 01:25 AM
HI

try this

So it should look something like


<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>
<%@ Register TagPrefix="cc2" TagName="AddressList" Src="~/SelectAddressControl.ascx" %>

<!-- This update panel is vital else the codebehind cannot show the modal dialog -->
<asp:UpdatePanel runat="server" ID="UpdatePanel1">
<ContentTemplate>
   <asp:ScriptManager ID="ScriptManager1" runat="server">
   </asp:ScriptManager>
   <asp:Label ID="LabelPostcode" runat="server" Text="Postcode" AssociatedControlID="Postcode"></asp:Label>
   <asp:TextBox ID="Postcode" runat="server" MaxLength="9"></asp:TextBox>

    <!-- The button  with the code behind -->
    <asp:Button ID="FindAddressButton" runat="server" Text="Find Address" CausesValidation="false" OnClick="FindAddress_Click" />
   

   <!-- The modal panel -->
   <asp:Panel ID="ModalPanel" runat="server" CssClass="modalPopup" >
      <!-- Inside we have a user control -->
      <cc2:AddressList ID="AddressList" runat="server" />
   </asp:Panel>

     
  <!-- We have to have a dummy control to hold the start event we handle in code behind -->
        <asp:Button ID="MpeFakeTarget" runat="server" CausesValidation="False" Style="display: none" />

        <!-- We have to use the long name for the cancel button as we have a user control-->
        <cc1:ModalPopupExtender ID="MPE" runat="server" TargetControlID="MpeFakeTarget"
          PopupControlID="ModalPanel" DropShadow="true" CancelControlID="ctl00$ctl00$ContentPlaceHolder1$ContentPlaceHolder1$AddressList$CancelButton"
          BackgroundCssClass="modalBackground"  />
      </ContentTemplate>
    </asp:UpdatePanel>
  Ravi S replied to balaji mogadali
04-Aug-11 01:27 AM
HI

The Modal Popup extender uses an ASP.NET Panel control, which opens up within the browser. Our next step is to create that Panel, and for this example, we will include a Repeater within to demonstrate our ability to display dynamic data within a popup, and not just static text. We will also add an Ok and a Cancel button, and demonstrate how we can pass values back from the Popup using JavaScript:


refer this

here is good example with coding
http://www.ajaxtutorials.com/ajax-tutorials/using-modalpopupextender-from-ajax-control-toolkit-c/
  Reena Jain replied to balaji mogadali
04-Aug-11 01:39 AM
hi,

Server side events do work with the ModalPopupExtender. What you need to do is to create a button with a display style set to none. Then set the TargetControlID property of the ModalPopupExtender to the hidden button ID.

<asp:Button ID="btnShowModal" runat="server" Text="Show" OnClick="btnShowModal_Click" />
<asp:Button ID="btnHidden" runat="server" Style="display: none" />
<ajaxControlToolkit:ModalPopupExtender ID="modalExtender" runat="server"
TargetControlID="btnHidden" PopupControlID="divId" />

In the OnClick handler show the modal:

modalExtender.Show();
  Vickey F replied to balaji mogadali
04-Aug-11 01:46 AM

use modalPopUpExtender like this-

<asp:Button ID="btnpopup" runat="server" Text="Button" />

<ajaxToolkit:ModalPopupExtender ID="mpe" runat="server" TargetControlID="btnpopup" PopupControlID="pnlpopup"

CancelControlID="btnCancelpopup" EnableViewState="true" />

<asp:Panel ID="pnlpopup" runat="server">

test

<asp:Button ID="btnCancelpopup" runat="server" Text="Button" />

</asp:Panel>

Hope this will help you.

  dipa ahuja replied to balaji mogadali
04-Aug-11 04:31 AM
Using Markup:


Untitled document
  <cc1:ModalPopupExtender TargetControlID="Button3" BackgroundCssClass="modalBackground"

PopupControlID="Panel1" CancelControlID="LinkButton4" PopupDragHandleControlID="btnMsg"

ID="ModalPopupExtender1" runat="server" />

 

<asp:Button ID="Button3" runat="server" Text="Take Input" />

 

<asp:Panel ID="Panel1" runat="server" Height="80" CssClass="ModalWindow">

<%--Take textboxes here--%>

<asp:LinkButton ID="LinkButton4" runat="server" Text="X" />

Records updated

</asp:Panel>

 

 
But if you want to call in codeBehind:

 protected void Button2_Click(object sender, EventArgs e)
  {
    ModalPopupExtender2.Show();
  }

  Rajdeep Nangre replied to balaji mogadali
14-May-12 05:37 AM
i want to show pop up list box on find button. the main problem is that find button in a grid view. so i am getting as error of that ModalPopupExtender id and find button id doesn't exist. please give some suggestion.
Create New Account
help
Enabled = status; else if (ctrl is Button) ((Button)ctrl).Enabled = status; else if (ctrl is RadioButton) ((RadioButton)ctrl).Enabled = status; else if (ctrl is ImageButton) ((ImageButton)ctrl).Enabled = status; else if (ctrl is CheckBox) ((CheckBox)ctrl).Enabled = status; else if (ctrl is DropDownList) ((DropDownList)ctrl).Enabled = status; else if (ctrl is HyperLink) ((HyperLink)ctrl).Enabled = status; } private void ClearControls
string ctrlStr = String.Empty; Control c = null ; foreach ( string ctl in page.Request.Form) { / / handle ImageButton controls . . . if (ctl.EndsWith( ".x" ) | | ctl.EndsWith( ".y" )) { ctrlStr = ctl.Substring(0, ctl.Length-2 ctl); } if (c is System.Web.UI.WebControls.Button | | c is System.Web.UI.WebControls.ImageButton) { control = c; break ; } } } return control; } private void InitializeComponent() { this .components = new System.ComponentModel.Container(); } } } What In the sample above, you can see that the downloadable demo has a textbox, a dropDownList, an ImageButton (google), a RadioButton, a Checkbox, two Button Controls, and a Linkbutton, all of which are configured to generate a postback event. In the pic above, I have just clicked on the Google ImageButton, and you can see the Label control at the top displaying it's ID property is a cause of considerable confusion among both the uninitiated and the expert. In addition, ImageButton type controls sport an additional "quasi-property" in their Id which identifies mouse x and
help me how to get the date / month / year in textbox by selecting month from dropdownlist control & calendar control. <table class = "newStyle10" style = "text-align:left; width: 63%;"> <tr> <td class class = "style11"> Magazine Name <span class = "style1"> *< / span> < / td> <td style = "height: 27px"> &nbsp;<asp:DropDownList ID = "DropDownList1" runat = "server"> < / asp:DropDownList> &nbsp;&nbsp;< / td> < / tr> <tr> <td class = "style11"> Subscription duration<br / > < / td> <td style = "height: 27px"> <asp:DropDownList ID = "DropDownList2" runat = "server" onselectedindexchanged = "DropDownList2_SelectedIndexChanged"> <asp:ListItem> - -select in months- -< / asp:ListItem> <asp:ListItem ListItem> 22< / asp:ListItem> <asp:ListItem> 23< / asp:ListItem> <asp:ListItem> 24< / asp:ListItem> < / asp:DropDownList> < / td> < / tr> <tr> <td class = "style11"> From Date<span style = "color:Red;"> *< / span> < / td> <td class = "style9"> <anthem:TextBox ID = "txtFromDate" runat = "server"> < / anthem:TextBox> <anthem:ImageButton ID = "ImageButton2" runat = "server" AutoUpdateAfterCallBack = "True" ImageUrl = "~ / App_Themes / Images / calendar_small.gif" onclick = "ImageButton2_Click" style = "height tr> <td class = "style11"> Complementary<span style = "color:Red;"> *< / span> < / td> <td class = "style6"> <anthem:RadioButton ID = "radiobtnYes" runat = "server" AutoUpdateAfterCallBack = "True" GroupName = "compl" Text = "Yes" / > <anthem:RadioButton ID = "radiobtnNo" runat = "server" AutoUpdateAfterCallBack = "True" GroupName = "compl" Text = "No" / > < / td> < / tr> <tr> <td class
class = "style11"> Magazine Name <span class = "style1"> *< / span> < / td> <td style = "height: 27px"> &nbsp;<asp:DropDownList ID = "DropDownList1" runat = "server"> < / asp:DropDownList> &nbsp;&nbsp;< / td> < / tr> <tr> <td class = "style11"> Subscription duration<br / > < / td> <td style = "height: 27px"> <asp:DropDownList ID = "DropDownList2" runat = "server" onselectedindexchanged = "DropDownList2_SelectedIndexChanged"> <asp:ListItem> - -select in months- -< / asp:ListItem> <asp:ListItem ListItem> 22< / asp:ListItem> <asp:ListItem> 23< / asp:ListItem> <asp:ListItem> 24< / asp:ListItem> < / asp:DropDownList> < / td> < / tr> <tr> <td class = "style11"> From Date<span style = "color:Red;"> *< / span> < / td> <td class = "style9"> <anthem:TextBox ID = "txtFromDate" runat = "server"> < / anthem:TextBox> <anthem:ImageButton ID = "ImageButton2" runat = "server" AutoUpdateAfterCallBack = "True" ImageUrl = "~ / App_Themes / Images / calendar_small.gif" onclick = "ImageButton2_Click" style = "height tr> <td class = "style11"> Complementary<span style = "color:Red;"> *< / span> < / td> <td class = "style6"> <anthem:RadioButton ID = "radiobtnYes" runat = "server" AutoUpdateAfterCallBack = "True" GroupName = "compl" Text = "Yes" / > <anthem:RadioButton ID = "radiobtnNo" runat = "server" AutoUpdateAfterCallBack = "True" GroupName = "compl" Text = "No" / > < / td> < / tr> <tr> <td class help me how to get the date / month / year in textbox by selecting month from dropdownlist control & calendar control. this is the source code of .aspx: <table class = "newStyle10" style = "text