469,609 Members | 1,450 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,609 developers. It's quick & easy.

Referencing a panel on a webform from an usercontrol

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
Lo*********@hotmail.com

//cogito ergo sum

Nov 17 '05 #1
2 1587
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=false .... </asp panel>
<user:control> //a function here turns the visibilty to
true </user:control>
</form>

Greetz,

Lokhan Wong
Lo*********@hotmail.com

//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
Nov 17 '05 #2
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.
-----Original Message-----
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=false .... </asp panel>
<user:control> //a function here turns the visibilty to
true </user:control>
</form>

Greetz,

Lokhan Wong
Lo*********@hotmail.com

//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 arecreating a dependancy in the containing page and introducing some tightcoupling that will affect the user control's re-use in other pages..
HTH
Kev
.

Nov 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Lokhan Wong | last post: by
6 posts views Thread by martin | last post: by
2 posts views Thread by Craig Douthitt via DotNetMonster.com | last post: by
1 post views Thread by Nathan Laff | last post: by
reply views Thread by devrayhaan | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.