Я создаю составной пользовательский элемент управления.Этот составной элемент управления содержит кнопку изображения.При нажатии кнопки изображения панель открывается как всплывающее окно. Эта панель выступает в качестве целевого элемента управления для DragablePanelExtender.Теперь проблема заключается в обратной передаче, положение перетаскиваемой панели сбрасывается.Кажется, он не сохраняет свою позицию.
для лучшего понимания, пожалуйста, проверьте код ..
public class HelpControl : CompositeControl
{
#region Control Property
/// <summary>
/// Width of the popup window
/// </summary>
private int m_width;
public int Width
{
get {
return m_width;
}
set {
m_width = value;
}
}
/// <summary>
/// Height of the popup window
/// </summary>
private int m_height;
public int Height
{
get
{
return m_height;
}
set
{
m_height = value;
}
}
/// <summary>
///
/// </summary>
private Boolean m_Exclusivity;
public Boolean Exclusivity
{
get
{
return m_Exclusivity;
}
set
{
m_Exclusivity = value;
}
}
/// <summary>
/// Help text to be displayed
/// </summary>
private String m_helpText;
public String HelpText
{
get
{
return m_helpText;
}
set
{
m_helpText = value;
}
}
/// <summary>
/// URL of the help text.
/// </summary>
private String m_helpTextURL;
public String HelpTextURL
{
get
{
return m_helpTextURL;
}
set
{
m_helpTextURL = value;
}
}
private String m_HeaderText;
public String HeaderText
{
get
{
return m_HeaderText;
}
set
{
m_HeaderText = value;
}
}
#endregion
#region Controls
private Panel m_PanelContainer;
private ModalPopupExtender m_ModalPopUp;
private Panel m_popupPanel;
private Panel m_HeaderPanel;
private Panel m_BodyPanel;
private ImageButton m_CloseButton;
private ImageButton m_HelpButton;
private HtmlLink Link;
private ScriptManager ScptMgr;
private ResizableControlExtender m_ResizableControl;
private DragPanelExtender m_DragPanelControl;
private Label m_HeaderLabel;
private HtmlGenericControl iframe = new HtmlGenericControl("iFrame");
private HiddenField position;
#endregion
protected override void OnInit(EventArgs e)
{
try
{
if (this.DesignMode == true)
return;
//register page state
Page.RegisterRequiresControlState(this);
//create controls
InitialiseControls();
}
catch (Exception ex)
{
string msg;
msg = ex.Message;
}
}
protected override void OnLoad(EventArgs e)
{
try
{
if (this.DesignMode == true)
return;
base.OnLoad(e);
if (Page == null || Page.Header == null || Page.ClientScript == null)
return;
Setup();
Control ResizableControlExtender = (Control)this.FindControl(m_ResizableControl.ID);
if (Exclusivity == true)
{
Control ModalPopupControl = (Control)this.FindControl(m_ModalPopUp.ID);
m_HelpButton.OnClientClick = string.Format("showModalComment('{0}','{1}');",
ModalPopupControl.ClientID, ResizableControlExtender.ClientID);
}
else
{
Control PopupControl = (Control)this.FindControl(m_popupPanel.ID);
Control DragabelExtender = (Control)this.FindControl(m_DragPanelControl.ID);
m_HelpButton.OnClientClick = string.Format("showPopComment('{0}','{1}','{2}');",
PopupControl.ClientID, ResizableControlExtender.ClientID, DragabelExtender.ClientID);
}
}
catch (Exception ex)
{
string msg;
msg = ex.Message;
}
}
protected override void OnPreRender(EventArgs e)
{
base.OnPreRender(e);
string resourceName = "Test.Help.ScriptFile.js";
ClientScriptManager cs = this.Page.ClientScript;
cs.RegisterClientScriptResource(typeof(HelpControl), resourceName);
}
[Bindable(true)]
[Category("Appearance")]
[DefaultValue("")]
[Localizable(true)]
protected override void RenderContents(HtmlTextWriter output)
{
try
{
if (this.DesignMode == true)
return;
//output.Write(Text);
base.RenderContents(output);
}
catch (Exception ex)
{
string msg;
msg = ex.Message;
}
}
public void Setup()
{
if (!Page.IsPostBack)
{
//BindServiceResultGrid();
}
//ClearMessages();
}
private void InitialiseControls()
{
if (Page == null || Page.Header == null || Page.ClientScript == null)
return;
//ensure embedded data is linked to the page
Link();
CreateMainPanel();
}
private void Link()
{
string url = Page.ClientScript.GetWebResourceUrl(this.GetType(), "Test.Help.Image.Style.css");
if (Page == null || Page.Header == null || Page.ClientScript == null)
return;
Link = new HtmlLink();
Link.Href = url;
Link.Attributes.Add("rel", "stylesheet");
Link.Attributes.Add("type", "text/css");
if (Page.Header != null)
Page.Header.Controls.AddAt(0, CSSLink);
}
private void CreateMainPanel()
{
m_PanelContainer = new Panel();
m_PanelContainer.ID = "HelpButtonMainPanel";
//
ScptMgr = ScriptManager.GetCurrent(this.Page);
//Add Help button to Main Panel
m_PanelContainer.Controls.Add(CreateHelpButton());
Controls.Add(m_PanelContainer);
CreateAjaxPopUp();
m_PanelContainer.Controls.Add(CreateResizableExtender());
}
private ImageButton CreateHelpButton()
{
m_HelpButton = new ImageButton();
m_HelpButton.ID = "btn_Help";
//m_HelpButton.ImageUrl = ImageURL;
m_HelpButton.ImageUrl = Page.ClientScript.GetWebResourceUrl(this.GetType(), "Test.Help.Image.Help.bmp");
m_HelpButton.AlternateText = "Help";
m_HelpButton.Click += new ImageClickEventHandler(m_HelpButton_Click);
return m_HelpButton;
}
protected void m_HelpButton_Click(object sender, ImageClickEventArgs e)
{
if (!Exclusivity)
{
m_popupPanel.Style.Add("z-index", "99999");
m_popupPanel.Style.Add("display", "block");
//m_popupPanel.Attributes["style"] = "LEFT: 150px; POSITION: absolute; TOP: 150px";
// m_popupPanel.Visible = true;
}
}
private void CreateAjaxPopUp()
{
m_popupPanel = new Panel();
m_popupPanel.ID = "PopUpPanel";
m_popupPanel.Width=Width;
m_popupPanel.Height=Height;
m_popupPanel.Style.Add("display", "none");
m_popupPanel.CssClass = "modalPopup";
//Create Header Panel
m_HeaderPanel = new Panel();
m_HeaderPanel.ID = "HeaderPanel";
//m_HeaderPanel.BackColor = System.Drawing.Color.AliceBlue;
m_HeaderPanel.CssClass = "HeaderStyle";
//Create Header Label
m_HeaderLabel = new Label();
m_HeaderLabel.Text = (HeaderText != String.Empty && HeaderText != null) ? HeaderText : "Information";
m_HeaderLabel.ForeColor = System.Drawing.Color.White;
m_HeaderLabel.CssClass = "HeaderLabelStyle";
m_HeaderLabel.ID = "HeaderLabel";
m_HeaderPanel.Controls.Add(m_HeaderLabel);
//Create Close button
m_CloseButton = new ImageButton();
m_CloseButton.ID = "btn_Close";
m_CloseButton.CssClass = "CloseButtonStyle";
m_CloseButton.ImageUrl = Page.ClientScript.GetWebResourceUrl(this.GetType(), "Test.Help.Image.Close.bmp");
// m_CloseButton.ImageAlign = ImageAlign.Right;
m_CloseButton.AlternateText = "Close";
m_CloseButton.Click += new ImageClickEventHandler(m_CloseButton_Click);
m_HeaderPanel.Controls.Add(m_CloseButton);
m_popupPanel.Controls.Add(m_HeaderPanel);
//Create Body Panel
m_BodyPanel = new Panel();
m_BodyPanel.ID = "BodyPanel";
// m_BodyPanel.Width = Width;
//m_BodyPanel.Height = (Height - Convert.ToInt16(m_HeaderLabel.Height.Value));
if (HelpTextURL == String.Empty || HelpTextURL==null)
{
Label HelpTextLabel = new Label();
HelpTextLabel.Text = HelpText != String.Empty ? HelpText.ToString() : "No Help provided!";
m_BodyPanel.Controls.Add(HelpTextLabel);
}
else
{
iframe.ID = "iFrame";
iframe.Attributes.Add("runat", "server");
iframe.Attributes.Add("width","100%");
iframe.Attributes.Add("height", "100%");
iframe.Attributes.Add("src",HelpTextURL.ToString());
iframe.Attributes.Add("framebroder","0");
iframe.Attributes.Add("scrolling","auto");
iframe.Style.Add("text-align", "justify");
m_BodyPanel.Controls.Add(iframe);
}
m_popupPanel.Controls.Add(m_BodyPanel);
m_PanelContainer.Controls.Add(m_popupPanel);
if (Exclusivity)
{
//Create Ajax popup extender
m_ModalPopUp = new ModalPopupExtender();
m_ModalPopUp.ID = "ModalPopup";
m_ModalPopUp.TargetControlID = "btn_Help";
m_ModalPopUp.PopupControlID = m_popupPanel.ID;
m_ModalPopUp.CancelControlID = "btn_Close";
m_ModalPopUp.DropShadow = false;
m_ModalPopUp.BackgroundCssClass = "modalBackground";
m_ModalPopUp.PopupDragHandleControlID = m_HeaderPanel.ID;
m_PanelContainer.Controls.Add(m_ModalPopUp);
}
else
{
m_DragPanelControl = new DragPanelExtender();
m_DragPanelControl.ID = "DragPanelControl";
m_DragPanelControl.DragHandleID = m_HeaderPanel.ID;
m_DragPanelControl.TargetControlID = m_popupPanel.ID;
m_PanelContainer.Controls.Add(m_DragPanelControl);
position = new HiddenField();
position.ID = "Position";
}
}
private ResizableControlExtender CreateResizableExtender()
{
m_ResizableControl = new ResizableControlExtender();
m_ResizableControl.ID = "ResizableControl";
m_ResizableControl.TargetControlID = m_popupPanel.ID;
m_ResizableControl.MinimumWidth = Width;
m_ResizableControl.MinimumHeight = Height;
m_ResizableControl.MaximumWidth = 1000;
m_ResizableControl.MaximumHeight = 1000;
m_ResizableControl.HandleOffsetX = 3;
m_ResizableControl.HandleOffsetY = 3;
// m_ResizableControl.BehaviorID = "ResizableControlBehavior";
m_ResizableControl.HandleCssClass = "handleImage";
m_ResizableControl.ResizableCssClass = "resizing";
if (HelpTextURL!= String.Empty && HelpTextURL!=null)
{
m_ResizableControl.OnClientResize = "OnResize" ;
}
return m_ResizableControl;
}
protected void m_CloseButton_Click(object sender, ImageClickEventArgs e)
{
if (Exclusivity)
{
m_ModalPopUp.Hide();
}
else
{
// this.m_PopUpControl.Cancel();
m_popupPanel.Style.Add("display", "none");
}
//throw new NotImplementedException();
}
}
}
код JavaScript
function showModalComment(ModalPopUp, ResizableControl) {
var popupControl = $find(ModalPopUp);
popupControl.show();
var resizeControl = $find(ResizableControl);
// alert(resizeControl);
resizeControl._resizeControl(0, 0, 0, 0);
resizeControl._rememberSize();
}
function showPopComment(PopUp, ResizableControl, DragableExtender) {
var popupControl = document.getElementById(PopUp);
popupControl.style.position = 'absolute';
var resizeControl = $find(ResizableControl);
resizeControl._resizeControl(0, 0, 0, 0);
resizeControl._rememberSize();
return;
}
function OnResize(sender, eventargs) {
var element = sender.get_element();
var heightStr = element.style.height;
var length=heightStr.length-2;
heightStr = heightStr.substring(0, length);
var height = heightStr;
var HeaderHt = sender.get_element().children[2].offsetHeight;
sender.get_element().children[3].style.height = height - HeaderHt + "px";
sender.get_element().children[3].firstChild.height = height - HeaderHt;
var widthStr = element.style.width;
length = widthStr.length - 2;
widthStr = widthStr.substring(0, length);
var width = sender.get_element().children[2].offsetWidth;
//alert(width + "," + sender.get_element().children[2].offsetWidth);
if (width != 0) {
sender.get_element().children[3].style.width = width-4 + "px";
sender.get_element().children[3].firstChild.width = width;
}
}