At the moment I’m building a CMS with ASP.NET, ASP.NET Ajax and the ASP.NET Ajax Toolkit. One of the great features that the AJAX Toolkit provides us is the possibility of adding modal popups.
I’m using them for gridviews that contains a lot of columns, and cannot be displayed in the page without the horizontal scroll. My solution for that is displaying the more important data, and then, when a row is selected, a detailform is displayed with all the data in a popup panel. My solution is based on Matt Berseth excellent post: Master-Detail with the GridView, DetailsView and ModalPopup Controls. This solves the problem of editing rows, but what happens when we want to add a new one?
The gridview control doesn’t have a built-in way of adding new items. One standard way of solving this is adding the add form in the footer of the gridview, but we don’t have the horizontal space needed for it if we have more data than the displayed on the gridview!
I planned to add a “Add element” link at my page, and adding a new popup for adding data. But it didn’t worked. My search of “multiple modal popups” didn’t give me any solutions. So I looked at what was happening there, and I created a simple test page like this:
<asp:LinkButton ID="lnk" runat="server" Text="hi"></asp:LinkButton>
<br />
<asp:LinkButton ID="lnk2" runat="server" Text="hi2"></asp:LinkButton>
<ajax:ModalPopupExtender ID="mpe" runat="server" TargetControlID="lnk" PopupControlID="pnl"
CancelControlID="close" />
<ajax:ModalPopupExtender ID="mpe2" runat="server" TargetControlID="lnk2" PopupControlID="pnl2"
CancelControlID="close2" />
<asp:Panel ID="pnl" runat="server" CssClass="popupPanel">
<div>
Hi!!!
</div>
<asp:Button ID="close" runat="server" Text="Close" />
</asp:Panel>
<asp:Panel ID="pnl2" runat="server" CssClass="popupPanel">
<div>
Hi2222!!!
</div>
<asp:Button ID="close2" runat="server" Text="Close" />
</asp:Panel>
If I show the first panel, and hide it, the second panel is never shown.
The problem is that, in the generated HTML code, the second panel is a child of the first one, instead of being at the same level on the DOM tree.
IMHO this is an Ajax Control Toolkit bug, and I hope that I’ll find time, and I will take a look and send a patch. But for now, I used a workaround. I placed the modal popup panels inside of another one wrapping each one, and it did the trick.
Hope this helps somebody.
UPDATE 2008/03/03: Merenzo has resolved the mistery. See the comments.
Filed under: Javascript, Tech | Tagged: AJAX, ajax control toolkit, ASP.NET, asp.net ajax, bug, Microsoft, modal popup, multiple













This did the trick. I was having the exact same issue.
Thanks!!
Подскажите шооблончег под WordPress 2.6.2, чтобы был похож на ваш penyaskitodice.wordpress.com.
Заранее благодарю)
Hi Hauxula,
This theme is Digg 3 Columns
Hope this helps.
PS: Please next time try to write in English, so I don’t have to bother my Russian friends (thanks Zitun)!
Interesnaya shtuka
Hello, I have the same problem. I followed your suggestion but i couldn’t get it to work. Could you post the working code?
Jason
Hi Jason,
I sent it to you by mail. Hope it helps.
could you pls send it to me by mail too…
+1 к предыдущему комменту
Can you send me the code too?
Hiya – I found this related post:
http://forums.asp.net/p/1157697/2719378.aspx
It claims that the problem is due to a missing semicolon in the AJAX script. Just wrapping the panel in another panel *usually* works, but doesn’t always (it didn’t in my case), as you can’t always guarantee that the offending line of script will be implicitly “ended” by whatever AJAX script is generated next.
However – once you’ve added the wrapping panel (e.g. “AjaxBugWorkaroundPanel”), you can then explicitly “end” the offending script by outputting your own semicolon as follows:
protected void AjaxBugWorkaroundPanel_PreRender(object sender, EventArgs e)
{
ScriptManager.RegisterStartupScript((Control)sender, sender.GetType(), Guid.NewGuid().ToString(), “;”, true);
}
All fixed! Who would’ve thought it.
cheers
merenzo.
ps: Specifically, in my case, I added the wrapping around the offending control only.
HTH!
cheers
merenzo.
ps: Specifically, in my case, I added the wrapping asp:Panel around the offending ajax:ModalPopupExtender control only.
HTH!
cheers
merenzo.
Thanks Merenzo, I’ll update the post accordingly.