By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,928 Members | 1,752 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,928 IT Pros & Developers. It's quick & easy.

panel's controls

P: n/a
Hi,

If I make a control that derives from panel, how can I persist the state of
the controls that are inside the panel when it is not rendered (visible =
false)?

The reason for this is that I'm making a custom user control that derives
from the Panel class. In the render method, I render some stuff and then I
do base.render if the panel is to be visible. If it's to be hidden, I don't
render it, but when I render it again, the controls that I've put in my
control at design time are all reset.) I think I'm missing something in this
:)

Thank you
Nov 18 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Can you give me an example of what you have within your panel? I just tried a simple example of my own and it persisted attributes I set at design time after I toggled the panel visible/invisible.
--Michael

Here is what I did

Public Class Panel : Inherits System.web.ui.webcontrols.Panel
Protected Overrides Sub Render(ByVal Output As HtmlTextWriter)
MyBase.Render(Output)
End Sub
End Class

<%@ Register TagPrefix="tnc" Namespace="tnc" Assembly="tnc" %>
<%@ Page Language="vb" AutoEventWireup="false" Codebehind="WebForm1.aspx.vb" Inherits="Intranet.WebForm1"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>WebForm1</title>
</head>
<body>

<form id="Form1" method="post" runat="server">
<tnc:panel id="pnlTest" runat="server">
<asp:textbox id="txtTest" runat="server" text="Hello!"></asp:textbox>
</tnc:panel>
<asp:button id="btnText" runat="server" text="Toggle"></asp:button>
</form>

</body>
</html>

Private Sub btnText_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnText.Click
If pnlTest.visible = False Then
pnlTest.Visible = True
Else
pnlTest.Visible = False
End If
End Sub

"Alexandre Soares" <so*********@hotmail.com> wrote in message news:Oe**************@TK2MSFTNGP10.phx.gbl...
Hi,

If I make a control that derives from panel, how can I persist the state of
the controls that are inside the panel when it is not rendered (visible =
false)?

The reason for this is that I'm making a custom user control that derives
from the Panel class. In the render method, I render some stuff and then I
do base.render if the panel is to be visible. If it's to be hidden, I don't
render it, but when I render it again, the controls that I've put in my
control at design time are all reset.) I think I'm missing something in this
:)

Thank you

Nov 18 '05 #2

P: n/a
I modified my example so that it fits what you did and you're right, the
info is persisted. However, in my original example, the button that
shows/hides the panel is rendered in the render method of the user control.
So in this render method, I always want to render the button, but not the
base panel. So if I do something like:

Protected Overrides Sub Render(ByVal Output As HtmlTextWriter)
button.Render(output)
if(panel must be visible) then
MyBase.Render(Output)
end if
End Sub

then the controls properties (like text) are not persisted. I don't know
why... :)
"Raterus" <ra*****@spam.org> a écrit dans le message de
news:%2****************@TK2MSFTNGP11.phx.gbl...
Can you give me an example of what you have within your panel? I just tried
a simple example of my own and it persisted attributes I set at design time
after I toggled the panel visible/invisible.
--Michael

Here is what I did

Public Class Panel : Inherits System.web.ui.webcontrols.Panel
Protected Overrides Sub Render(ByVal Output As HtmlTextWriter)
MyBase.Render(Output)
End Sub
End Class

<%@ Register TagPrefix="tnc" Namespace="tnc" Assembly="tnc" %>
<%@ Page Language="vb" AutoEventWireup="false" Codebehind="WebForm1.aspx.vb"
Inherits="Intranet.WebForm1"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>WebForm1</title>
</head>
<body>

<form id="Form1" method="post" runat="server">
<tnc:panel id="pnlTest" runat="server">
<asp:textbox id="txtTest" runat="server" text="Hello!"></asp:textbox>
</tnc:panel>
<asp:button id="btnText" runat="server" text="Toggle"></asp:button>
</form>

</body>
</html>

Private Sub btnText_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnText.Click
If pnlTest.visible = False Then
pnlTest.Visible = True
Else
pnlTest.Visible = False
End If
End Sub

"Alexandre Soares" <so*********@hotmail.com> wrote in message
news:Oe**************@TK2MSFTNGP10.phx.gbl...
Hi,

If I make a control that derives from panel, how can I persist the state of the controls that are inside the panel when it is not rendered (visible =
false)?

The reason for this is that I'm making a custom user control that derives
from the Panel class. In the render method, I render some stuff and then I
do base.render if the panel is to be visible. If it's to be hidden, I don't render it, but when I render it again, the controls that I've put in my
control at design time are all reset.) I think I'm missing something in this :)

Thank you

Nov 18 '05 #3

P: n/a
Actually my button is an anchor tag that fires a javascript postback (my
class implements IPostBackEventHandler to catch the postback event and
change the panel visibility state)

"Raterus" <ra*****@spam.org> a écrit dans le message de
news:%2****************@TK2MSFTNGP11.phx.gbl...
Can you give me an example of what you have within your panel? I just tried
a simple example of my own and it persisted attributes I set at design time
after I toggled the panel visible/invisible.
--Michael

Here is what I did

Public Class Panel : Inherits System.web.ui.webcontrols.Panel
Protected Overrides Sub Render(ByVal Output As HtmlTextWriter)
MyBase.Render(Output)
End Sub
End Class

<%@ Register TagPrefix="tnc" Namespace="tnc" Assembly="tnc" %>
<%@ Page Language="vb" AutoEventWireup="false" Codebehind="WebForm1.aspx.vb"
Inherits="Intranet.WebForm1"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>WebForm1</title>
</head>
<body>

<form id="Form1" method="post" runat="server">
<tnc:panel id="pnlTest" runat="server">
<asp:textbox id="txtTest" runat="server" text="Hello!"></asp:textbox>
</tnc:panel>
<asp:button id="btnText" runat="server" text="Toggle"></asp:button>
</form>

</body>
</html>

Private Sub btnText_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnText.Click
If pnlTest.visible = False Then
pnlTest.Visible = True
Else
pnlTest.Visible = False
End If
End Sub

"Alexandre Soares" <so*********@hotmail.com> wrote in message
news:Oe**************@TK2MSFTNGP10.phx.gbl...
Hi,

If I make a control that derives from panel, how can I persist the state of the controls that are inside the panel when it is not rendered (visible =
false)?

The reason for this is that I'm making a custom user control that derives
from the Panel class. In the render method, I render some stuff and then I
do base.render if the panel is to be visible. If it's to be hidden, I don't render it, but when I render it again, the controls that I've put in my
control at design time are all reset.) I think I'm missing something in this :)

Thank you

Nov 18 '05 #4

P: n/a
Do you realize that sub Render will never be called if the control.visible = false ?
So checking for visibility in Render is pointless, since it will always be true.

"Alexandre Soares" <so*********@hotmail.com> wrote in message news:Ov**************@tk2msftngp13.phx.gbl...
I modified my example so that it fits what you did and you're right, the
info is persisted. However, in my original example, the button that
shows/hides the panel is rendered in the render method of the user control.
So in this render method, I always want to render the button, but not the
base panel. So if I do something like:

Protected Overrides Sub Render(ByVal Output As HtmlTextWriter)
button.Render(output)
if(panel must be visible) then
MyBase.Render(Output)
end if
End Sub

then the controls properties (like text) are not persisted. I don't know
why... :)


"Raterus" <ra*****@spam.org> a écrit dans le message de
news:%2****************@TK2MSFTNGP11.phx.gbl...
Can you give me an example of what you have within your panel? I just tried
a simple example of my own and it persisted attributes I set at design time
after I toggled the panel visible/invisible.
--Michael

Here is what I did

Public Class Panel : Inherits System.web.ui.webcontrols.Panel
Protected Overrides Sub Render(ByVal Output As HtmlTextWriter)
MyBase.Render(Output)
End Sub
End Class

<%@ Register TagPrefix="tnc" Namespace="tnc" Assembly="tnc" %>
<%@ Page Language="vb" AutoEventWireup="false" Codebehind="WebForm1.aspx.vb"
Inherits="Intranet.WebForm1"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>WebForm1</title>
</head>
<body>

<form id="Form1" method="post" runat="server">
<tnc:panel id="pnlTest" runat="server">
<asp:textbox id="txtTest" runat="server" text="Hello!"></asp:textbox>
</tnc:panel>
<asp:button id="btnText" runat="server" text="Toggle"></asp:button>
</form>

</body>
</html>

Private Sub btnText_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnText.Click
If pnlTest.visible = False Then
pnlTest.Visible = True
Else
pnlTest.Visible = False
End If
End Sub



"Alexandre Soares" <so*********@hotmail.com> wrote in message
news:Oe**************@TK2MSFTNGP10.phx.gbl...
Hi,

If I make a control that derives from panel, how can I persist the state

of
the controls that are inside the panel when it is not rendered (visible =
false)?

The reason for this is that I'm making a custom user control that derives
from the Panel class. In the render method, I render some stuff and then I
do base.render if the panel is to be visible. If it's to be hidden, I

don't
render it, but when I render it again, the controls that I've put in my
control at design time are all reset.) I think I'm missing something in

this
:)

Thank you


Nov 18 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.