Lokhan Wong wrote:
My question is whether it's possible to change the
properties of a panel, that resides on the webform
containing the usercontrol, in the usercontrol itself.
Like this:
<form>
<asp:panel visibility=fals e .... </asp panel>
<user:contro l> //a function here turns the visibilty to
true </user:control>
</form>
Greetz,
Lokhan Wong
Lo*********@ho tmail.com
//cogito ergo sum
This is possible:
In the usercontrol code behind I have:
private void Page_Load(objec t sender, System.EventArg s e)
{
// Put user code to initialize the page here
if(Page.IsPostB ack)
{
// Find the control
System.Web.UI.W ebControls.Pane l ctrl =
(System.Web.UI. WebControls.Pan el) Page.FindContro l("MyPanel");
// Make it visible
ctrl.Visible = true;
// Abd Add some text
Label lbl = new Label();
lbl.Text = " Now you see me!";
ctrl.Controls.A dd(lbl);
}
}
On the aspx page containing the usercontrol:
<form id="Form1" method="post" runat="server">
<asp:panel id="MyPanel" visible="False" runat="server"> Hello</asp:panel>
<kk:MyControl id="MyControl" runat="server" />
</form>
From a design perspective I'd be wary of doing this because you are
creating a dependancy in the containing page and introducing some tight
coupling that will affect the user control's re-use in other pages..
HTH
Kev