Wednesday, March 21, 2012

panel's controls

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 youCan 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=3D"tnc" Namespace=3D"tnc" Assembly=3D"tnc" %>
<%@. Page Language=3D"vb" AutoEventWireup=3D"false" =
Codebehind=3D"WebForm1.aspx.vb" Inherits=3D"Intranet.WebForm1"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>WebForm1</title>
</head>
<body>
<form id=3D"Form1" method=3D"post" runat=3D"server">
<tnc:panel id=3D"pnlTest" runat=3D"server">
<asp:textbox id=3D"txtTest" runat=3D"server" =
text=3D"Hello!"></asp:textbox>
</tnc:panel>
<asp:button id=3D"btnText" runat=3D"server" =
text=3D"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 =3D False Then
pnlTest.Visible =3D True
Else
pnlTest.Visible =3D False
End If
End Sub
"Alexandre Soares" <soares4ever@.hotmail.com> wrote in message =
news:OeHO5IOSEHA.3608@.TK2MSFTNGP10.phx.gbl...
> Hi,
>=20
> 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 =3D
> false)?
>=20
> 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
> :)
>=20
> Thank you
>=20
>
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" <raterus@.spam.org> a crit dans le message de
news:%23oefCWOSEHA.1568@.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" <soares4ever@.hotmail.com> wrote in message
news:OeHO5IOSEHA.3608@.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
>
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" <raterus@.spam.org> a crit dans le message de
news:%23oefCWOSEHA.1568@.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" <soares4ever@.hotmail.com> wrote in message
news:OeHO5IOSEHA.3608@.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
>
Do you realize that sub Render will never be called if the =
control.visible =3D false ?
So checking for visibility in Render is pointless, since it will always =
be true.
"Alexandre Soares" <soares4ever@.hotmail.com> wrote in message =
news:OvW8gjOSEHA.3596@.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:
>=20
> Protected Overrides Sub Render(ByVal Output As HtmlTextWriter)
> button.Render(output)
> if(panel must be visible) then
> MyBase.Render(Output)
> end if
> End Sub
>=20
> then the controls properties (like text) are not persisted. I don't =
know
> why... :)
>=20
>=20
> "Raterus" <raterus@.spam.org> a =E9crit dans le message de
> news:%23oefCWOSEHA.1568@.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
>=20
> Here is what I did
>=20
> Public Class Panel : Inherits System.web.ui.webcontrols.Panel
> Protected Overrides Sub Render(ByVal Output As HtmlTextWriter)
> MyBase.Render(Output)
> End Sub
> End Class
>=20
> <%@. Register TagPrefix=3D"tnc" Namespace=3D"tnc" Assembly=3D"tnc" %>
> <%@. Page Language=3D"vb" AutoEventWireup=3D"false" =
Codebehind=3D"WebForm1.aspx.vb"
> Inherits=3D"Intranet.WebForm1"%>
> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
> <html>
> <head>
> <title>WebForm1</title>
> </head>
> <body>
>=20
> <form id=3D"Form1" method=3D"post" runat=3D"server">
> <tnc:panel id=3D"pnlTest" runat=3D"server">
> <asp:textbox id=3D"txtTest" runat=3D"server" =
text=3D"Hello!"></asp:textbox>
> </tnc:panel>
> <asp:button id=3D"btnText" runat=3D"server" =
text=3D"Toggle"></asp:button>
> </form>
>=20
> </body>
> </html>
>=20
> Private Sub btnText_Click(ByVal sender As System.Object, ByVal e =
As
> System.EventArgs) Handles btnText.Click
> If pnlTest.visible =3D False Then
> pnlTest.Visible =3D True
> Else
> pnlTest.Visible =3D False
> End If
> End Sub
>=20
>=20
>=20
> "Alexandre Soares" <soares4ever@.hotmail.com> wrote in message
> news:OeHO5IOSEHA.3608@.TK2MSFTNGP10.phx.gbl...
state
> of
(visible =3D
derives
then I
I
> don't
my
in
> this
>=20
>

0 comments:

Post a Comment