Problems with div and Panel with VS

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • tshad

    Problems with div and Panel with VS

    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"t o 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">E mployee 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 <divto <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'b ut
    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

    #2
    Re: Problems with div and Panel with VS

    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.C ontrol. The Visible
    property belongs to .Net controls, which DIV is not. unfortunately just
    adding on a "runat=serv er" 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.getEle mentById('txtBo xwhatever').

    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 misunderstandin g 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" <tscheiderich@f tsolutions.comw rote in message
    news:O1xI4$Z3GH A.3428@TK2MSFTN GP05.phx.gbl...
    >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">E mployee 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 <divto <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'b ut
    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.
    >

    Comment

    • tshad

      #3
      Re: Problems with div and Panel with VS


      "Tim_Mac" <tim.mackey@com munity.nospamwr ote in message
      news:OB3Zjia3GH A.5040@TK2MSFTN GP02.phx.gbl...
      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.C ontrol. The
      Visible property belongs to .Net controls, which DIV is not.
      unfortunately just adding on a "runat=serv er" 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 programmaticall y 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.

      Learn with interactive lessons and technical documentation, earn professional development hours and certifications, and connect with the community.


      >
      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.getEle mentById('txtBo xwhatever').
      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 misunderstandin g 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" <tscheiderich@f tsolutions.comw rote in message
      news:O1xI4$Z3GH A.3428@TK2MSFTN GP05.phx.gbl...
      >>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">E mployee 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 <divto <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.Form s.0.TextBox1' is null or not an object.
      >>
      >
      >

      Comment

      • Tim_Mac

        #4
        Re: Problems with div and Panel with VS

        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=serverbec ause 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><tabl e 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


        Comment

        • tshad

          #5
          Re: Problems with div and Panel with VS

          "Tim_Mac" <tim.mackey@com munity.nospamwr ote in message
          news:OdPeyRl3GH A.1252@TK2MSFTN GP04.phx.gbl...
          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=serverbec ause 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><tabl e 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">E mployee 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;fon t-weight:bold;hei ght:24px;">Empl oyee
          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 <TBODYthat 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:Paneltag and the closing tag </TBODYinside the 2nd
          </asp:Panel>. I kept getting an error saying the <TBODYtags 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
          >

          Comment

          Working...