User-2127570633 posted
Hi, I'm creating a custom user control for asp.net wich is embedding a ModalPopupExtender. The modal popup extender is added to the controls list in the ShowPopup method handling the imageclick event. The problem is that when another postback is fired i
can't access the modalpopupextender to call methods such as the close method (that is what i'm going to do), i've tried to lookup the control from the controls collection of the UserControl via the FindControl method but i can't find it ! Below is the code...
please help me !
public abstract class AbstractFieldUserControl : System.Web.UI.UserControl
{
public AbstractFieldUserControl()
{
this.Controls.Add(new LiteralControl() { ID = "LI_Code"} );
this.Controls.Add(new LiteralControl(" - ") { ID = "LI_Sep"});
this.Controls.Add(new LiteralControl() { ID = "LI_Description"});
ImageButton img = new ImageButton();
img.ID = "IM_Open";
img.ImageUrl = "~/img/edit.png";
img.ImageAlign = ImageAlign.AbsMiddle;
img.Click += new ImageClickEventHandler(this.ShowPopup);
this.Controls.Add(img);
}
private void ShowPopup(object sender, ImageClickEventArgs e)
{
if (this.PopupContent == null)
throw new NullReferenceException("PopupContent propery cannot be null");
Button b = new Button();
b.ID = "BT_Target";
b.Style.Add("display", "none");
this.Controls.Add(b);
ImageButton imOpen = (ImageButton)FindControl("IM_Open");
ModalPopupExtender popup = new ModalPopupExtender();
popup.TargetControlID = b.ID;
popup.OkControlID = imOpen.ID;
popup.ID = "Popup";
popup.PopupControlID = this.PopupContent.ClientID;
InitPopupContent();
this.Controls.Add(popup);
popup.Show();
}
public Control PopupContent { set; get; }
public abstract void InitPopupContent();
protected void SetCodeDescription(object sender, EventArgs e)
{
string[] args = ((Button)sender).CommandArgument.ToString().Split(';');
(FindControl("LI_Code") as LiteralControl).Text = args[0];
(FindControl("LI_Description") as LiteralControl).Text = args[1];
}
protected void SetCodeDescription(string code,string description)
{
(FindControl("LI_Code") as LiteralControl).Text = code;
(FindControl("LI_Description") as LiteralControl).Text = description;
}
public string Code {
set { (FindControl("LI_Code") as LiteralControl).Text = value; }
get { return (FindControl("LI_Code") as LiteralControl).Text; }
}
public string Description
{
set { (FindControl("LI_Description") as LiteralControl).Text = value; }
get { return (FindControl("LI_Description") as LiteralControl).Text; }
}
}