panel's controls

Discussion in 'ASP .Net' started by Alexandre Soares, Jun 2, 2004.

  1. 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
    Alexandre Soares, Jun 2, 2004
    #1
    1. Advertising

  2. Alexandre Soares

    Raterus Guest

    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" <> wrote in message news:...
    > 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
    >
    >
    Raterus, Jun 2, 2004
    #2
    1. Advertising

  3. 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" <> a écrit dans le message de
    news:%...
    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" <> wrote in message
    news:...
    > 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
    >
    >
    Alexandre Soares, Jun 2, 2004
    #3
  4. 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" <> a écrit dans le message de
    news:%...
    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" <> wrote in message
    news:...
    > 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
    >
    >
    Alexandre Soares, Jun 2, 2004
    #4
  5. Alexandre Soares

    Raterus Guest

    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" <> wrote in message news:...
    > 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" <> a écrit dans le message de
    > news:%...
    > 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" <> wrote in message
    > news:...
    > > 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
    > >
    > >

    >
    >
    Raterus, Jun 3, 2004
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Harry
    Replies:
    3
    Views:
    529
    Harry Singh
    Nov 10, 2003
  2. HS1
    Replies:
    3
    Views:
    474
  3. HS1
    Replies:
    4
    Views:
    8,282
    Babu Kalakrishnan
    Dec 8, 2004
  4. JC
    Replies:
    1
    Views:
    737
    Michael Rauscher
    Aug 9, 2006
  5. Ulf Meinhardt
    Replies:
    0
    Views:
    599
    Ulf Meinhardt
    Jul 7, 2009
Loading...

Share This Page