Problems with div and Panel with VS

Discussion in 'ASP .Net' started by tshad, Sep 21, 2006.

  1. tshad

    tshad Guest

    I am trying to hide and show certain parts of my code (which I have no
    problem doing with DW). In VS 2003, it won't let you use <div
    runat="server"> to section of parts of my code in a table. This is during
    compilation (build).

    My code is:

    <TABLE id="Table1" style="WIDTH: 864px; HEIGHT: 177px" cellSpacing="1"
    cellPadding="1"
    width="864" border="0">
    <div ID="LogonPanel" Runat="server">
    <TR>
    <TD colSpan="3">
    <asp:label id="Label1" runat="server" Height="24px" Font-Bold="True"
    Font-Size="Larger">Employee Login</asp:label></TD>
    </TR>
    ....
    </div>
    </Table>

    The errors I get are:
    1. Could not find any attribute 'Visible' of element 'div'.
    2. Per the active schema, the element 'div' cannot be nested within 'table'.

    If I change the <div> to <asp:panel>, I can't access the Textbox.Text?

    It worked fine until I used the Panel. I just put the Panel around the
    Logon section and my code wants to access the Textbox that has the user name
    in it:

    The problem seems to be that when the Panel is not visible anything inside
    is not rendered. This is not the case when using <div runat='server'> but
    VS won't let me use that.

    Or is there something I need to do to tell VS to handle it?

    Thanks,

    Tom
    'Document.Forms.0.TextBox1' is null or not an object.
     
    tshad, Sep 21, 2006
    #1
    1. Advertising

  2. tshad

    Tim_Mac Guest

    hi,
    the problem isn't with VS 2003. the DIV HTML element has no property called
    Visible because it doesn't inherit from System.Web.UI.Control. The Visible
    property belongs to .Net controls, which DIV is not. unfortunately just
    adding on a "runat=server" does not make the control a .Net control. it
    just gives you server side access to a HTML element.

    it sounds like you might make better use of PlaceHolders which leave no
    markup on the page, and can be used for Showing/Hiding other controls or
    HTML. also the VS designer will probably complain if you put server
    controls in invalid places, such as between TABLE and TR tags. it may
    refuse to draw the page and throw you into HTML mode.

    also, you can't nest a DIV directly inside a TABLE tag because it is invalid
    HTML by any standard.

    the javascript you're using also appears to be nonstandard. I would
    recommend document.getElementById('txtBoxwhatever').

    when a Panel is not visible, none of its contents are rendered. This is the
    point of setting Visible=False, i.e. the user shouldn't be able to see it,
    and by inference the HTML shouldn't be rendered.

    do you want to use client-side show/hide functionality? it sounds like your
    DW background is making life difficult. if you hide a control on the
    server, then the rendered HTML is not included for that control. if you
    hide it on the client, the HTML never changes and the browser simply makes
    the element invisible. i'm sure you know that already but it sounds like
    there is some misunderstanding between the effects of server-side and
    client-side code.

    i hope this answers your question, let me know if anything i've written
    isn't clear.
    tim.


    "tshad" <> wrote in message
    news:O1xI4$...
    >I am trying to hide and show certain parts of my code (which I have no
    >problem doing with DW). In VS 2003, it won't let you use <div
    >runat="server"> to section of parts of my code in a table. This is during
    >compilation (build).
    >
    > My code is:
    >
    > <TABLE id="Table1" style="WIDTH: 864px; HEIGHT: 177px" cellSpacing="1"
    > cellPadding="1"
    > width="864" border="0">
    > <div ID="LogonPanel" Runat="server">
    > <TR>
    > <TD colSpan="3">
    > <asp:label id="Label1" runat="server" Height="24px" Font-Bold="True"
    > Font-Size="Larger">Employee Login</asp:label></TD>
    > </TR>
    > ...
    > </div>
    > </Table>
    >
    > The errors I get are:
    > 1. Could not find any attribute 'Visible' of element 'div'.
    > 2. Per the active schema, the element 'div' cannot be nested within
    > 'table'.
    >
    > If I change the <div> to <asp:panel>, I can't access the Textbox.Text?
    >
    > It worked fine until I used the Panel. I just put the Panel around the
    > Logon section and my code wants to access the Textbox that has the user
    > name in it:
    >
    > The problem seems to be that when the Panel is not visible anything inside
    > is not rendered. This is not the case when using <div runat='server'> but
    > VS won't let me use that.
    >
    > Or is there something I need to do to tell VS to handle it?
    >
    > Thanks,
    >
    > Tom
    > 'Document.Forms.0.TextBox1' is null or not an object.
    >
     
    Tim_Mac, Sep 21, 2006
    #2
    1. Advertising

  3. tshad

    tshad Guest

    "Tim_Mac" <> wrote in message
    news:...
    > hi,
    > the problem isn't with VS 2003. the DIV HTML element has no property
    > called Visible because it doesn't inherit from System.Web.UI.Control. The
    > Visible property belongs to .Net controls, which DIV is not.
    > unfortunately just adding on a "runat=server" does not make the control a
    > .Net control. it just gives you server side access to a HTML element.


    Actually, DIV with runat="Server" (which allows the visibility property)
    works great. Even DW complains about it not being standard. But I had
    found out about this a couple of years ago and have been using it since. It
    works great. Not sure why. But obviously it obviously is handled correctly
    by the server side.

    For example:

    Before Div
    <div ID="test" Visible="true" runat='server'>This is a test</div>
    After Div

    will render as:
    Before Div
    <div id="test">This is a test</div>
    After Div

    and

    Before Div
    <div ID="test" Visible="false" runat='server'>This is a test</div>
    After Div

    renders as:

    Before Div

    After Div

    This allows you to control your text and controls programmatically like
    using an asp:panel. There was something different about the Panel and Div -
    but I can't remember what it was.

    These links also talk about it.
    http://www.thescripts.com/forum/thread532743.html
    http://msdn.microsoft.com/msdnmag/issues/03/05/CuttingEdge/
    http://cfouquet.blogspot.com/

    >
    > it sounds like you might make better use of PlaceHolders which leave no
    > markup on the page, and can be used for Showing/Hiding other controls or
    > HTML. also the VS designer will probably complain if you put server
    > controls in invalid places, such as between TABLE and TR tags. it may
    > refuse to draw the page and throw you into HTML mode.
    >


    Actually, Div leaves no markup if visible=false. It renders exactly the
    same (so not sure why we have Div for this if Panel does the job). Here is
    the result if I change the above Div to asp:panel.

    Before Div
    <div id="test">
    This is a test
    </div>
    After Div

    Exactly the same.
    > also, you can't nest a DIV directly inside a TABLE tag because it is
    > invalid HTML by any standard.
    >

    If this is the right, then I don't believe you would be able to use Panel
    inside you repeaters and datagrids as they just translate into tables.

    I use Div's inside tables all the time.

    > the javascript you're using also appears to be nonstandard. I would
    > recommend document.getElementById('txtBoxwhatever').


    What Javascript? From another post?
    >
    > when a Panel is not visible, none of its contents are rendered. This is
    > the point of setting Visible=False, i.e. the user shouldn't be able to see
    > it, and by inference the HTML shouldn't be rendered.
    >

    Same as Div.

    I was mistaken about being able to access a textbox when visible=false for
    Div. I thought I was able to access it.

    > do you want to use client-side show/hide functionality? it sounds like
    > your DW background is making life difficult. if you hide a control on the
    > server, then the rendered HTML is not included for that control. if you
    > hide it on the client, the HTML never changes and the browser simply makes
    > the element invisible. i'm sure you know that already but it sounds like
    > there is some misunderstanding between the effects of server-side and
    > client-side code.


    No. I didn't want client side functionality. I use Div to show/hide areas
    of my screen depending on what the client has entered or what I get back
    from a database.

    My problem is the VS is preventing me from doing what I have been doing for
    years and apparently is valid. I was curious if there was a way to get VS
    to allow this. I have pages I am trying to move to my VS project that use
    this technique and I don't want to have to recode these pages.

    Thanks,

    Tom

    >
    > i hope this answers your question, let me know if anything i've written
    > isn't clear.
    > tim.
    >
    >
    > "tshad" <> wrote in message
    > news:O1xI4$...
    >>I am trying to hide and show certain parts of my code (which I have no
    >>problem doing with DW). In VS 2003, it won't let you use <div
    >>runat="server"> to section of parts of my code in a table. This is during
    >>compilation (build).
    >>
    >> My code is:
    >>
    >> <TABLE id="Table1" style="WIDTH: 864px; HEIGHT: 177px" cellSpacing="1"
    >> cellPadding="1"
    >> width="864" border="0">
    >> <div ID="LogonPanel" Runat="server">
    >> <TR>
    >> <TD colSpan="3">
    >> <asp:label id="Label1" runat="server" Height="24px" Font-Bold="True"
    >> Font-Size="Larger">Employee Login</asp:label></TD>
    >> </TR>
    >> ...
    >> </div>
    >> </Table>
    >>
    >> The errors I get are:
    >> 1. Could not find any attribute 'Visible' of element 'div'.
    >> 2. Per the active schema, the element 'div' cannot be nested within
    >> 'table'.
    >>
    >> If I change the <div> to <asp:panel>, I can't access the Textbox.Text?
    >>
    >> It worked fine until I used the Panel. I just put the Panel around the
    >> Logon section and my code wants to access the Textbox that has the user
    >> name in it:
    >>
    >> The problem seems to be that when the Panel is not visible anything
    >> inside is not rendered. This is not the case when using <div
    >> runat='server'> but VS won't let me use that.
    >>
    >> Or is there something I need to do to tell VS to handle it?
    >>
    >> Thanks,
    >>
    >> Tom
    >> 'Document.Forms.0.TextBox1' is null or not an object.
    >>

    >
    >
     
    tshad, Sep 21, 2006
    #3
  4. tshad

    Tim_Mac Guest

    hi tom,
    yes i see now that the HtmlControls also have a Visible server side
    property.

    based on your original post, you had problems with an invisible control not
    rendering any HTML. from what you've just written you seem to understand
    this already so i'm not sure what the problem was. VS only complained about
    the <div runat=server> because you had it in between a TABLE and TR tag.

    you can of course use Panels inside DataGrids and Repeaters. the problem
    was that you had nested the tags in an incorect order. the browser will
    still render it and you'll probably get funny gaps in the table, but you
    can't expect consistent results with this kind of invalid markup:
    <table><div><tr><td>

    if you put a Panel inside a DataGrid, you'll get something like this:
    <Table id='DataGrid1'><tr><td><table id='Panel1'>... this is Valid markup.

    your post included a javascript error on the last line.

    you can use server-divs, PlaceHolders, or Panels, all to achieve the same
    effect. VS does not have a problem with any. my point about PlaceHolders
    was simply that they do not leave a DIV or TABLE tag behind when they render
    (Visible). obviously an invisible control will not render any HTML.

    tim
     
    Tim_Mac, Sep 22, 2006
    #4
  5. tshad

    tshad Guest

    "Tim_Mac" <> wrote in message
    news:...
    > hi tom,
    > yes i see now that the HtmlControls also have a Visible server side
    > property.
    >
    > based on your original post, you had problems with an invisible control
    > not rendering any HTML. from what you've just written you seem to
    > understand this already so i'm not sure what the problem was. VS only
    > complained about the <div runat=server> because you had it in between a
    > TABLE and TR tag.


    The problem was that I had 2 errors that it wouldn't build from - I am
    trying to find out if there is a setting that will allow me to do it.

    1. Could not find any attribute 'Visible' of element 'div'.
    2. Per the active schema, the element 'div' cannot be nested within 'table'.

    As you saw, there is a Visible attribute - if you also have runat=visible.
    As you said, it will not render anything if set to false. So they should
    allow it. It is valid.

    The other error seems to be fine (at least for IE) so this should be allowed
    also. Especially since they render Panel to Div inside of a table for IE.

    >
    > you can of course use Panels inside DataGrids and Repeaters. the problem
    > was that you had nested the tags in an incorect order. the browser will
    > still render it and you'll probably get funny gaps in the table, but you
    > can't expect consistent results with this kind of invalid markup:
    > <table><div><tr><td>
    >
    > if you put a Panel inside a DataGrid, you'll get something like this:
    > <Table id='DataGrid1'><tr><td><table id='Panel1'>... this is Valid markup.
    >


    Actually, this is not the case in IE (it is in Mozilla and Firefox,
    however).

    I have the following code:

    <TABLE id="Table1" style="WIDTH: 864px; HEIGHT: 177px" cellSpacing="1"
    cellPadding="1"
    width="864" border="0">
    <asp:panel id="LogonPanel" Runat="server">
    <TR>
    <TD colSpan="3">
    <asp:label id="Label1" runat="server" Height="24px" Font-Bold="True"
    Font-Size="Larger">Employee Login</asp:label></TD>
    </TR>
    ....

    and the viewsource shows:

    <TABLE id="Table1" style="WIDTH: 864px; HEIGHT: 177px" cellSpacing="1"
    cellPadding="1"
    width="864" border="0">
    <div id="LogonPanel">
    <TR>
    <TD colSpan="3">
    <span id="Label1"
    style="font-size:Larger;font-weight:bold;height:24px;">Employee
    Login</span></TD>
    </TR>

    My problem is that VS should allow this if you want it - they obviously do
    it.

    > your post included a javascript error on the last line.
    >
    > you can use server-divs, PlaceHolders, or Panels, all to achieve the same
    > effect. VS does not have a problem with any. my point about PlaceHolders
    > was simply that they do not leave a DIV or TABLE tag behind when they
    > render (Visible). obviously an invisible control will not render any
    > HTML.


    You right I can do all these but they're messages are not correct (Visible
    is valid).

    The other thing that was driving me crazy was the stupid <TBODY> that kept
    showing up and messing up my code. I actually had 2 Panel sections back to
    back. When one if visible the other isn't. It kept putting the <TBODY>
    inside the first <asp:panel> tag and the closing tag </TBODY> inside the 2nd
    </asp:panel>. I kept getting an error saying the <TBODY> tags were nested
    incorrectly (the problem was they did it). I kept having to delete these to
    make my code work. Not sure what was causing it but when I made certain
    changes - it kept showing up. Must have done this about 10 times.

    Thanks,

    Tom
    >
    > tim
    >
     
    tshad, Sep 22, 2006
    #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. K Viltersten

    <div ... /> and <div ...></div>

    K Viltersten, Mar 30, 2009, in forum: ASP .Net
    Replies:
    4
    Views:
    750
  2. Robin Wenger
    Replies:
    0
    Views:
    2,934
    Robin Wenger
    Aug 18, 2011
  3. Chris

    Grid Layout Panel and Panel in the Designer

    Chris, Aug 28, 2003, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    203
    Chris
    Aug 28, 2003
  4. Dwayne Madsen

    Q: Div A inside Div B is larger than Div B

    Dwayne Madsen, Jun 1, 2005, in forum: Javascript
    Replies:
    1
    Views:
    191
    David Dorward
    Jun 1, 2005
  5. mscir
    Replies:
    3
    Views:
    315
    Martin Honnen
    Jun 26, 2005
Loading...

Share This Page