I created a variant of a Button that does some clientside action OnMouseDown. I just want to share this, so here is the code:
public class DynamicModalButton : Button
{
public string ModalPopUpHeaderClientTarget { get; set; }
public string ModalPopUpBodyClientTarget { get; set; }
public string ModalPopUpFooterClientTarget { get; set; }
public string ModalPopUpHeader
{
get { return (string)(ViewState["ModalPopUpHeader"] ?? string.Empty); }
set { ViewState["ModalPopUpHeader"] = value; }
}
public string ModalPopUpBody
{
get { return (string)(ViewState["ModalPopUpBody"] ?? string.Empty); }
set { ViewState["ModalPopUpBody"] = value; }
}
public string ModalPopUpFooter
{
get { return (string)(ViewState["ModalPopUpFooter"] ?? string.Empty); }
set { ViewState["ModalPopUpFooter"] = value; }
}
protected override void OnPreRender(System.EventArgs e)
{
getOnMouseDownEvents();
base.OnPreRender(e);
}
private void getOnMouseDownEvents()
{
string sOnMouseDown = string.Empty;
if (!String.IsNullOrEmpty(ModalPopUpHeaderClientTarget)) { sOnMouseDown += buildOnMouseDown(ModalPopUpHeaderClientTarget, ModalPopUpHeader); }
if (!String.IsNullOrEmpty(ModalPopUpBodyClientTarget)) { sOnMouseDown += buildOnMouseDown(ModalPopUpBodyClientTarget, ModalPopUpBody); }
if (!String.IsNullOrEmpty(ModalPopUpFooterClientTarget)) { sOnMouseDown += buildOnMouseDown(ModalPopUpFooterClientTarget, ModalPopUpFooter); }
if (!String.IsNullOrEmpty(sOnMouseDown)) { this.Attributes.Add("onmousedown", sOnMouseDown); }
}
private string buildOnMouseDown(string sTarget, string sText)
{
string sBuildMouseDown = "document.getElementById('" + sTarget + "').innerHTML = \"" + sText + "\";";
return sBuildMouseDown;
}
What it actualy does is adding som properties to a standard asp.net button, and you can use the properties to set text to targets clientside. This is handy when you want to define what text is showing in the ModalPopup on the button.
After building the controll you can use it like this:
So everytime you hit that button the client side OnMouseDown event sends the text from the properties to the Paragraphs.
If you put the paragraphs in a panel for a ModalPopupExtender, and add a ModalPopupExtender for the button, you can set the content in the PopUp from the Button.
larsbehner
Member
38 Points
9 Posts
ModalPopupExtender with dynamic content
May 07, 2012 03:31 PM|LINK
Hi!
I created a variant of a Button that does some clientside action OnMouseDown. I just want to share this, so here is the code:
public class DynamicModalButton : Button { public string ModalPopUpHeaderClientTarget { get; set; } public string ModalPopUpBodyClientTarget { get; set; } public string ModalPopUpFooterClientTarget { get; set; } public string ModalPopUpHeader { get { return (string)(ViewState["ModalPopUpHeader"] ?? string.Empty); } set { ViewState["ModalPopUpHeader"] = value; } } public string ModalPopUpBody { get { return (string)(ViewState["ModalPopUpBody"] ?? string.Empty); } set { ViewState["ModalPopUpBody"] = value; } } public string ModalPopUpFooter { get { return (string)(ViewState["ModalPopUpFooter"] ?? string.Empty); } set { ViewState["ModalPopUpFooter"] = value; } } protected override void OnPreRender(System.EventArgs e) { getOnMouseDownEvents(); base.OnPreRender(e); } private void getOnMouseDownEvents() { string sOnMouseDown = string.Empty; if (!String.IsNullOrEmpty(ModalPopUpHeaderClientTarget)) { sOnMouseDown += buildOnMouseDown(ModalPopUpHeaderClientTarget, ModalPopUpHeader); } if (!String.IsNullOrEmpty(ModalPopUpBodyClientTarget)) { sOnMouseDown += buildOnMouseDown(ModalPopUpBodyClientTarget, ModalPopUpBody); } if (!String.IsNullOrEmpty(ModalPopUpFooterClientTarget)) { sOnMouseDown += buildOnMouseDown(ModalPopUpFooterClientTarget, ModalPopUpFooter); } if (!String.IsNullOrEmpty(sOnMouseDown)) { this.Attributes.Add("onmousedown", sOnMouseDown); } } private string buildOnMouseDown(string sTarget, string sText) { string sBuildMouseDown = "document.getElementById('" + sTarget + "').innerHTML = \"" + sText + "\";"; return sBuildMouseDown; }What it actualy does is adding som properties to a standard asp.net button, and you can use the properties to set text to targets clientside. This is handy when you want to define what text is showing in the ModalPopup on the button.
After building the controll you can use it like this:
And you have to add the targets:
So everytime you hit that button the client side OnMouseDown event sends the text from the properties to the Paragraphs.
If you put the paragraphs in a panel for a ModalPopupExtender, and add a ModalPopupExtender for the button, you can set the content in the PopUp from the Button.
Lars