Home » Asp.net

ModalpopupExtender to display dynamic content from database and content from form's control

Dear All,


I have a grid, in that i have edit button column, If user wants to click on the edit button I need to open a modal window to display the records for the particular row data from database.


And also I am using SMS form to send sms, If user click on the send button I need to open the modal window and to dislpay a preview of the sms from the textbox of the same form.


Please help me to achieve these two functionality.


Thanks in advance.




Arun Kumar


1 Answer Found



Ok, after searching on how to do this and trying many different ways and failing, I finally got something working. 
So, I decided to post it here to help anyone else that might be trying to do the same thing. 
If anyone sees a better way to do this then please let me know.

I want to populate an update panel with addresses so I use a repeater. 
I want the user to click a link and that causes a modal popup to appear for the user to enter thier address so that
they can get driving directions to the address listed in the Repeater.  I needed a way to get the address the user
was driving to, to also be inside the modal popup because I need to pass it along later.  The reason the list of
addresses are in an updatepanel are for paging purposes.  I've used a simple version of the repeater in this example though.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

      <form id="Form1" method="post" runat="server">
         <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>

  <asp:UpdatePanel ID="myMainPanel" runat="server" EnableViewState=false>
               <asp:Repeater ID="rptItems" runat="server" EnableViewState=false>
       <asp:Label                        runat="server" 
                        Text=<%#Eval("Address").ToString + ", " + Eval("State").ToString + ", " + Eval("Zip").ToString%> 
                     <asp:LinkButton                        ID="Directions"                        runat="server" 
                        CommandArgument=<%#Eval("Address").ToString + ", " + Eval("State").ToString + ", " + Eval("Zip").ToString%>>


         <asp:Button runat="server" ID="btnHidden" Style="display: none;" EnableViewState=false />

         <cc1:ModalPopupExtender            ID="ModalPopupExtender"            runat="server"            TargetControlID="btnHidden"            BackgroundCssClass="ModalBackground" 
            CancelControlID="mpeCancel"            PopupControlID="mpePanel" >

         <asp:Panel ID="mpePanel" runat="server" style="display:none;" EnableViewState=false CssClass="ModalPopup">

            <asp:UpdatePanel ID="mpeUpdatePanel" runat="server" EnableViewState=false UpdateMode=conditional>
                     <table cellpadding=0 cellspacing=0>
                           <td align=left>
                              <asp:Label ID="lblFrom" runat="server" Text="From:" EnableViewState=false></asp:Label>
                           <td align=left>
                              <asp:TextBox                                 ID="txtUserAddress"                                 EnableViewState="False"                                 runat="server"                                 Width="250px"                                 BorderStyle="Solid"                                 Height="16px"                                 Wrap="False"                                 BorderWidth="1px"                                 BorderColor="Black"
                           <td align=left>
                               <asp:Label ID="lblTo" runat="server" Text="To:" EnableViewState=false></asp:Label>
                           <td align=left>
                              <asp:TextBox                                 ID="txtLocationAddress"                                 EnableViewState="False"                                 runat="server"                                 Width="250px"                                 BorderStyle="Solid"                                 Height="16px"                                 Wrap="False"                                 BorderWidth="1px"                                 BorderColor="Black"
                           <td height=5px></td>

               <table cellpadding=0 cellspacing=0>
                        <td align=left>
                           <asp:Button ID="mpeOk" runat="server" Text="Get Directions" EnableViewState=false /> 
                        <td align=right width=250px>
                           <asp:Button ID="mpeCancel" runat="server" Text="Cancel" EnableViewState=false />



Make double sure you have the correct DOCTYPE at the beginning of your page!

I didn't want the ModalPopupExtender inside my main UpdatePanel because I need a full postback to open a new browser window later,
plus I didn't want 10-15 copies of  the extender on each page anyway.
I created the "fake" button btnHidden to link the ModalPopupExtender to since it requires a TargetControlID.

Now, in the UpdatePanel that surrounds the Repeater I created a LinkButton for the user to click to get directions. 
Notice it has OnCommand and CommandArguments. The CommandArgument is the address of the location the user wants directions to.

Here is the codebehind for the OnCommand sub he LinkButton:

Public Sub Directions_Command(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.CommandEventArgs)
   txtLocationAddress.Text = e.CommandArgument
End Sub

In this sub I set the text of a textbox that is inside the panel that pops up with the ModalPopupExtender to the address the user will
be driving to.   But it's not that simple... I had to put an update panel inside that panel then manually update it once I pushed the
address into the textbox otherwise it never populated.  To do that, the updatepanel inside the popup also has to have it's UpDateMode
property set to "conditional".  Once the update panel is told to update, the only thing left to do is show the ModalPopupExtender.  

Bam! There you have it, dynamic modalpopup without having to put it in every row of your repeater with a DynamicContext setting. 

The key is manually firing an updatepanel that resides in the popup then manually showing the popup.

But wait!  I wanted to show the user the driving directions in a new window...  

The first thing I did was make sure the OKControlID wasn't set on my ModalPopupExtender because I don't want it to just close the popup
without doing anything. The next important thing to do is make sure the ModalPopupExtender's "Ok" and "Cancel" buttons are NOT inside
the UpdatePanel that is inside the ModalPopupExtender because we want a full postback.  Then I simply put code inside click event of the
"OK' button. 

Protected Sub mpeOk_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles mpeOk.Click

   If txtUserAddress.Text = ""Then
      Exit Sub
   End If

   Dim strurl As String = "http://maps.google.com/maps?saddr=" & txtUserAddress.Text & "&daddr=" & txtLocationAddress.Text

   Dim strCommand As String = "window.open('" & strurl & "','','');"

   Response.Write("<!DOCTYPE html PUBLIC " & """" & "-//W3C//DTD XHTML 1.0 Transitional//EN" & """" & "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" & """" & ">" & vbCrLf)
   Response.Write("<script>" & vbCrLf)
   Response.Write(strCommand & vbCrLf)
   Response.Write("<" & Chr(47) & "script>")

End Sub

I build the url and then write it out again so that when the page loads, it pops open the directions in a new window.  This isn't the best
method in the world but currently we have no other way to force a new window open since it's client side.

Also, note that I had to write out the doctype again.  The reason I did that is because when this script is placed into the page is is placed
above the existing doctype and it messes things up. I hope to figure out a way to have the script or a function pre-built into the page and
maybe have it look for some change that I make on postback to fire.

I hope that this helps someone that has been trying this themselves and having a hard time finding how to do it.  I would also welcome any
comments on a better way to accomplish this.



Hi folks,


I have this piece of code which paint an ImageButton and show a dynamic ModalPopupExtender (with 2 buttons btnGuardar and btCancel).

The issue is neither btGuardar.Click nor btHidden.Click events are raised but ImageButton Click event is raised correctly.

Please can you help mee?


protected HtmlGenericControl _divControlContainer = new HtmlGenericControl();
protected ModalPopupExtender _PopupHandler = new ModalPopupExtender();

protected override void CreateChildControls() { Page.Trace.Write("void CreateChildControls()"); _divControlContainer = new HtmlGenericControl("ivContenedor"); Button btHidden = new Button(); btHidden.ID = "hiddenTargetControlForModalPopup"; btHidden.Style.Add(HtmlTextWriterStyle.Display, "none"); btHidden.Click += new EventHandler(event_HiddenTargetModalPopup_Click); //EVENT NOT RISED _divControlContainer.Controls.Add(btHidden); ImageButton ib = new ImageButton(); ib.ID = "btUploadImage"; ib.ImageUrl = "~/Imagenes/UIControlImageViewer/upload.png"; ib.Height = new Unit("16px"); ib.Width = new Unit("16px"); ib.Click += new ImageClickEventHandler(event_UploadFile_Click); //EVENT RAISED CORRECTLY _divControlContainer.Controls.Add(ib); this.Controls.Add(_divControlContainer); base.CreateChildControls(); }

private void event_HiddenTargetModalPopup_Click(object sender, EventArgs e)

private void event_UploadSaveFile_Click(object sender, EventArgs e)

private void event_UploadFile_Click(object sender, ImageClickEventArgs e) { Panel container = new Panel(); container.Style.Add(HtmlTextWriterStyle.Display, "none"); container.ID = "container"; container.CssClass = "modalPopup"; container.Height = new Unit("100px"); container.Width = new Unit("300px"); Button btGuardar = new Button(); btGuardar.ID = "ButtonOK"; btGuardar.Text = "OK"; btGuardar.Click += new EventHandler(event_UploadSaveFile_Click); //EVENT NOT RAISED Button btCancel= new Button(); btCancel.ID = "Button2"; btCancel.Text = "CANCEL"; container.Controls.Add(btGuardar); container.Controls.Add(btCancel); dynamic_PopupHandler(container, btCancel); _PopupHandler.Show(); } private void dynamic_PopupHandler( Panel container, //Button ok, Button cancel) { _PopupHandler = new ModalPopupExtender(); _PopupHandler.ID = "Dynamic_Popup"; _PopupHandler.PopupControlID = container.ID; _PopupHandler.TargetControlID = "hiddenTargetControlForModalPopup"; _PopupHandler.DropShadow = true; _PopupHandler.CancelControlID = cancel.ID; _PopupHandler.BackgroundCssClass = "modalBackground"; _PopupHandler.BehaviorID = "hiddenTargetControlForModalPopup"; //_PopupHandler.OkControlID = ok.ID; _divControlContainer.Controls.Add(container); _divControlContainer.Controls.Add(_PopupHandler); }





I'd like to use a TreeView control to display database data in a windows form with VB2008. All the information what I found is related to a website design, but I'm working on a database program (sql2005), where I'd like the user to see the structure what he/she make up with a TreeView like control. Just something like that when you explore your hard disk.

How can I do that?




I have customized a Page Layout to include a custom Data Form View Web Part that will allow users to enter comments on a news story page in a publishing site.

I was having a difficult time because when I clicked the button to save the data to the list, everything saved correctly, but the control was redirecting me to the AllItems.aspx page of the list.  This wasn't the desired behavior since the end user would prefer to see that their comment was posted on the news story page and wouldn't know what the AllItems.aspx page was for.

The save button that was created in the XSL seciton of the web part was:

<SharePoint: SaveButton runat="server" ControlMode="New" id="savebutton1" />

Microsoft has documented a RedirectUrl property on this button that I figured could change what page was loaded after the user saved the form data.  However, try as I might I could not get it to work.

Some more searching lead me to this article:


Which details how to create a "Form Action" for a save button rendered in the XSL of a DataFormWebPart.  This was a great article, but it doesn't detail the code that Sharepoint Designer outputs for this action.  After following the instructions, I discovered this code for a button:

<input type="button" value="Save" name="btnSave" onclick="javascript: {ddwrt:GenFireServerEvent('__commit;__redirect={}')}" />

When used instead of my SharePoint: SaveButton above, the form saved it's data correctly, and the current page that the form was submitted from was reloaded for the user.

You could also put any URL in the __redirect={} that you want, for example __redirect={http://www.google.com} or __redirect={/news/PressReleases/}

Notice that there are no quotes around the URLs passed into the __redirect directive.

Didn't find this documented anywhere, but it seemed pretty useful so I thought I would share.



Hello Everyone,

  I am getting this error "Only Content controls are allowed directly in a content page that contains Content controls". I am using a single aspx page and not a separate cs file. Now, to write code inside aspx page, I am using <script> tag. Now, my problem is inside one of the method I have to use <script> tag. Now, when i use that this error comes. Eg

  <script runat="server">

 ........inside it coding done

  // Method inside which I have to use this tag again

  public void abc()


........initially some code.........

Response.Write("<script>document.getElementById('PaylForm').submit();</script></body></html>");   //This gives error




Thanks in Advance.



FYi I am using SPD.

I saved dispform.aspx with the new name dispform1.aspx. Then I did some modification in the pages, everything was correctly. After some time I re-open new page using SPD, I am  not able to open the page in design/code mode. It is not giving me any error only showing message in status bar retrieving dispform1.aspx. I wait almost 1 hours, but no luck.

When I try to run this new page I am getting following error

"Only Content controls are allowed directly in a content page that contains Content controls"

Earlier it was working and I have not made any changes.

I need to recover it, as I did customize the whole page, please advise



   For Creating a database dynamically  i created a webpart, but there will be an exception comes at runtime.Following  code shows the exception :

System.Security.SecurityException: Access denied. at Microsoft.SharePoint.Administration.SPPersistedObject.Update() at Microsoft.SharePoint.Administration.SPServer.Update() at Microsoft.SharePoint.Administration.SPPersistedObject.Update(Boolean ensure) at Microsoft.SharePoint.Administration.SPPersistedChildCollection`1.Add(T newObj, Boolean ensure) at Microsoft.SharePoint.Administration.SPPersistedChildCollection`1.Ensure(T newObj) at Microsoft.SharePoint.Administration.SPContentDatabaseCollection.Add(Guid newDatabaseId, String strDatabaseServer, String strDatabaseName, String strDatabaseUsername, String strDatabasePassword, Int32 warningSiteCount, Int32 maximumSiteCount, Int32 status, Boolean provision, Boolean allowUpgrade, Boolean flushChangeLog) at Microsoft.SharePoint.Administration.SPContentDatabaseCollection.Add(String strDatabaseServer, String strDatabaseName, String strDatabaseUsername, String strDatabasePassword, Int32 warningSiteCount, Int32 maximumSiteCount, Int32 status, Boolean provision, Boolean allowUpgrade) at Microsoft.SharePoint.Administration.SPContentDatabaseCollection.Add(String strDatabaseServer, String strDatabaseName, String strDatabaseUsername, String strDatabasePassword, Int32 warningSiteCount, Int32 maximumSiteCount, Int32 status) at CommunityWB.CommunityWB.btn_Sumbit_Click(Object sender, EventArgs e) The Zone of the assembly that failed was: MyComputer

If anyone know the answer,Reply please..


I'm using SharePoint 2010 and InfoPath 2010 to create a custom Edit form. The form is basically an issue/change tracker in which I want to display the related task from a subsite. So to be clear I have an issue/change that I am documenting and a dropdown to select the related task based on the selected client (subsite). I have all of this working properly but I want to make the related task title a linked title which links to the display form for the related task. So I need to dynamically create and store a hyperlink to the display form of the selected task, not just the task title in plain text. Currently the data (Task Title) is being stored in a single line text field in a SharePoint list. The data source for the task title is just a standard task list on a subsite with some customized fields added but the linked title and forms haven't been modified at all.

I know what the link should be ie https://mysite/subsite/DispForm.aspx?ID=1 and dynamically if I was in SPD it would be https://mysite/subsite/DispForm.aspx?ID={@ID} but how do I add dynamic content to the value being stored by the InfoPath form? The value for the ID that it displays in the drop down list box properties form is Value: d:ID but it won't let me manually alter this value to wrap a url around it. All I can seem to do is select another field from the current data source using the select xpath button. Any suggestions as to how I should go about getting my desired functionality with the linked Task Title?



I'm trying to add controls dynamically with the help of document fragments in VSTO 2010. Short version (where frag.docx contains a content control with the tag "tag1"):


string xPathName = "ns:employees/ns:employee[2]/ns:name";
Globals.ThisDocument.SelectContentControlsByTag("tag1")[1].XMLMapping.SetMapping(xPathName, ThisDocument.prefix, Globals.ThisDocument.employeeXMLPart);

Complete code can be found here: http://www.mediafire.com/?3505iovi814ez7w

This was adapted from the code posted here: http://msdn.microsoft.com/en-us/library/bb398244.aspx

The first problem is that the custom xml part doesn't seem to be updated when I change the data of the custom controls. E.g. change the name of an employee.

The second problem is that the title dropdown list isn't populated with it's proper values from the schema.

What have I missed? Is there a better way of doing this?


Hey community,

I am quite new to the WPF and currently try to create a custom window control for an entity editor. The editor will hold a domainobject (e.g. an employee of a company) whose fields can be editted using the editor visually (name, surname, corporate id, etc...), and then be saved back to the database using generic "Save" and "Apply" buttons.

Since I want the editor to be reusable for different entities, I intended to have the common buttons for saving and so on at the bottom of the window, and the rest be filled dynamically with editor-specific controls (textboxes, labels...).

In the end, it should be used something like this using XAML:

<EditorWindow x:Class="Redheads.PmisSharp.Client.Ui.Wnd.Editor.EditorBaseWindow"
       d:DesignHeight="300" d:DesignWidth="300">
		<!-- The actual individual controls for this editor -->

In this example the mentioned "Save" / "Apply" buttons should be implicitly added at the bottom of the window. But I don't know how to achieve this at the moment. Can anyone give me a clue or point me to some links that can help me out? I think that ControlTemplates might do the trick, but I am not so sure about that.

Any advice is appreciated, thanks!

- PuerNoctis



Am having a column in my database which contains id and path for images and not image files...

i need to display images dynamically in SSRS 2005 based on input ID ...

As i have only the path in my database , i couldnt display image based on path..


Any help would be greatly appreciated...






I want to Display N-Heirarchical Menu using Dynamic Repeater Control along with CheckBoxes.

If Suppose i am having 3 level Menus i need to create 3 Repeaters Dynamically along with CheckBoxes beside of that sub Menus


Hi All,


          How to display dynamic  header for datalist control(Dates are dynamic).Also i want header in each row.I want something like this.Words in bold are headers.Header also in each row.8/1/2010,8/8/2010,8/15/2010,8/22/2010 are dynamic dates whic changes every month based on user selecting date from datecontrol.


      HeadCount       8/1/2010       8/8/2010      8/15/2010     8/22/2010

 Forecaster HC         447                  446                       441            432

Agents Scheduled   447                  446                       441           432





Hi all,

I have a strange behavior with my forms. The infopath template is defined as Content Type for my Form library, in the advanced settings I have checked "Display as a Web page" for the "Opening browser-enabled documents" setting. Despite that when the client is availble on the computer which is browsing the Form Library, I'm asked to "Open", "Save" or "Cancel" instead of opening the form in the browser.

Any idea why this is happening ?



I've created a custom content type in VS. In "Elements.xml" file of my content type, I added my custom application page as new form and deployed as feature.


When I'm calling application page with direct url ( http://myportal/_layouts/mycustom/customForm.aspx ), page is running as expected. But if I try to add an item related with my custom content type in a sharepoint list, "new form page" response empty content with ribbon bar.

My custom application page:

<%@AssemblyName="$SharePoint.Project.AssemblyFullName$"%><%@ImportNamespace="Microsoft.SharePoint.ApplicationPages"%><%@RegisterTagprefix="SharePoint"Namespace="Microsoft.SharePoint.WebControls"Assembly="Microsoft.SharePoint, Version=, Culture=neutral, PublicKeyToken=71e9bce111e9429c"%><%@RegisterTagprefix="Utilities"Namespace="Microsoft.SharePoint.Utilities"Assembly="Microsoft.SharePoint, Version=, Culture=neutral, PublicKeyToken=71e9bce111e9429c"%><%@RegisterTagprefix="asp"Namespace="System.Web.UI"Assembly="System.Web.Extensions, Version=, Culture=neutral, PublicKeyToken=31bf3856ad364e35"%><%@ImportNamespace="Microsoft.SharePoint"%><%@AssemblyName="Microsoft.Web.CommandUI, Version=, Culture=neutral, PublicKeyToken=71e9bce111e9429c"%><%@RegisterTagprefix="WebPartPages"Namespace="Microsoft.SharePoint.WebPartPages"Assembly="Microsoft.SharePoint, Version=, Culture=neutral, PublicKeyToken=71e9bce111e9429c"%><%@PageLanguage="C#"AutoEventWireup="true"CodeBehind="EditTest.aspx.cs"Inherits="Test1ContentType.Layouts.MyCustom.EditTest"DynamicMasterPageFile="~masterurl/default.master"%><asp:ContentID="PageHead"ContentPlaceHolderID="PlaceHolderAdditionalPageHead"runat="server"></asp:Content><asp:ContentID="Main"ContentPlaceHolderID="PlaceHolderMain"runat="server">
My Content
Application Page
My Application Page

I think that there should be -must have controls- in the application page of content types form(?) Could anyone post a base aspx page for content type forms? Or is there another trick for form pages?

Thanks in advance.




We need to have the display from to give an option to select from 2 content types on a list.

The view should automatically select the content type based on the item.

Any suggestions?

Thanks for your help in advance.




I have an Activity Designer Library which contains multiple designers.  I want each of these designers to use a wpf custom control that I created.  This custom control contains some ContentPresenters and the content is supplied by each of the activity designers.

For the wpf custom control, it is simply a single control that contains a Themes\Generic.xaml file.  When my designers set the content in my custom control, it does not display.  However, if I create the exact same custom control, build it as part of a separate WPF Custom Control library and use it in my designers, then the content displays fine.  It is only when the custom control is built as part of the Activity Designer Library that it does not work.  Do you know why this might be happening?

Thank you.




I've used HTML Help workshop to develop a help system for the web.  I've setup a frameset with 2 frames ('left' and 'contents'). The 'left' frame contains a file called 'TOC.htm', with the HTML Help ActiveX control to display the TOC. The default frame in which topics should appear is set as the 'contents' frame, in both the .hhc and TOC.htm files.

However, when I view the frameset in IE7, and click on an item in the TOC, the content that should have been displayed in the 'contents' frame, is displayed in the 'left' frame. Why?

Thanks in advance.


Hi all,

I have a small issue with ModalPopupExtender. It opens in an Iframe initially, and shows the page: add_contact.aspx After I have entered the contact details, the IFrame redirects to the contact_details.aspx page to show what I have loaded.

The problem is when I close that modalpopup-window and click again to show the modalpopup, the iFrame shows the contact_details.aspx page, and not the add_contact.aspx page.

Anyways, I can resolve this, without using modalPopup.show() in code behind?



I have a user control (ascx) vs 2010 that contains a modalpopup extender thats popup control is an asp:panel.  In that Panel I have an update panel and a contenttemplate inside the upd panel.  It is a pretty simple example of its use, in that I have list box allowing the users to create a new row in a table. 

However, when I click targetcontrol, the background changes to the expended modal background, but instead of being able to use the listbox, everything in the content panel is the same as the background and none of the controls on the panel are enabled.  In other words, the entire page is loaded dimgray, including the updatearea.

Not sure what is going on here, but any help would be appreciated.


<< Previous      Next >>

Microsoft   |   Windows   |   Visual Studio   |   Sharepoint   |   Azure