Referencing a panel on a webform from an usercontrol

  • Thread starter Thread starter Lokhan Wong
  • Start date Start date
L

Lokhan Wong

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=false .... </asp panel>
<user:control> //a function here turns the visibilty to
true </user:control>
</form>

Greetz,

Lokhan Wong
(e-mail address removed)

//cogito ergo sum
 
Lokhan said:
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=false .... </asp panel>
<user:control> //a function here turns the visibilty to
true </user:control>
</form>

Greetz,

Lokhan Wong
(e-mail address removed)

//cogito ergo sum
This is possible:

In the usercontrol code behind I have:

private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
if(Page.IsPostBack)
{
// Find the control
System.Web.UI.WebControls.Panel ctrl =
(System.Web.UI.WebControls.Panel) Page.FindControl("MyPanel");

// Make it visible
ctrl.Visible = true;

// Abd Add some text
Label lbl = new Label();
lbl.Text = " Now you see me!";
ctrl.Controls.Add(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
 
It worked. Thanks for the info.

The reason why I used it this way is because I wanted to
make a registering page made of several steps. Putting
every step in a seperate page would be unwise. Also
putting every step in a seperate panel on the page would
make the page unmanageable. So by putting every step in
its own usercontrol I can manage the code more easily.
 
Back
Top