Saturday, March 24, 2012

Problem Dragging ModalPopupExtender

In the ModalPopupExtender when I drag the popup it always snaps back to the middle.

If I place the JavaScript code that is in the sample page on my page then I am able to drag the popup around the page and it stays where I drop it as expected.

<script type="text/javascript"> // The following snippet works around a problem where FloatingBehavior // doesn't allow drops outside the "content area" of the page - where "content // area" is a little unusual for our sample web pages due to their use of CSS // for layout. function setBodyHeightToContentHeight() { document.body.style.height = Math.max(document.documentElement.scrollHeight, document.body.scrollHeight) + "px"; } setBodyHeightToContentHeight(); $addHandler(window, "resize", setBodyHeightToContentHeight); </script>

The JavaScript says it's just a work around due to how the sample page is structured. But, in my page I'm not using any type of css layout (other than for the ModalPopupExtender background). I just have a HyperLink, Panel for the popup, Panel for the popup handle and ModalPopupExtender.

<%@dotnet.itags.org. Page Language="C#" %><%@dotnet.itags.org. Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><script runat="server">protected void ButtonOK_Click(object sender, EventArgs e){Response.Redirect("myModal.aspx");}</script><html xmlns="http://www.w3.org/1999/xhtml"><head runat="server"><title>Untitled Page</title><style type="text/css">/*Modal Popup*/.modalBackground{background-color: #000000;filter: alpha(opacity=30);opacity: 0.3;}</style></head><body><form id="form1" runat="server"><div><asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager><asp:HyperLink ID="LinkShow" runat="server">Click to show dialog</asp:HyperLink><br /><br /><br /><asp:Panel ID="PanelPopup" runat="server"><asp:Panel ID="PanelPopupHandle" runat="server">This is the popup handle</asp:Panel>This is the content of the popup panel<br /><asp:Button ID="ButtonOK" runat="server" Text="OK" onclick="ButtonOK_Click" /><asp:Button ID="ButtonCancel" runat="server" Text="Cancel" /></asp:Panel><br /><cc1:ModalPopupExtender ID="ModalPopupExtender1" runat="server" BackgroundCssClass="modalBackground"TargetControlID="LinkShow" CancelControlID="ButtonCancel" Drag="True" PopupControlID="PanelPopup"PopupDragHandleControlID="PanelPopupHandle"></cc1:ModalPopupExtender></div></form></body></html>

Am I missing something or do I need to always place that piece of JavaScript on pages that use the ModalPopupExtender?

this is problem due to not specifying height and width for popup panel
try adding height and width:-

<asp:PanelID="PanelPopup"runat="server"Width="300"Height="300"BorderWidth="1"BackColor="AliceBlue">


Yes, that works. Thank you!


As soon as I click on the dragable header of the ModalPopupExtender popup, the panel moves to the right. It keeps doing this every time I click on it.

I have read every work around on the web to fix this and nothing has worked for me:

1. Added the javascriptsetBodyHeightToContentHeight()

2. Set the Height and Width of the body tag

3. Modified FloatingBahavior.js:

this.onDragEnd =function(canceled) {

canceled =false; <-- added this

4. Set the width and height in the last post.

Nothing has worked for me! Even setting Drag="true" or Drag="false" seems to not work at all.

I could sure use an answer.

No comments:

Post a Comment