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="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
>
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 = 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:
>
> 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
>
0 comments:
Post a Comment