Referencing a panel on a webform from an usercontrol

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
 
K

Kevin Kenny

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
 
L

Lokhan Wong

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top