InnerHtml of Div ...

Last post 05-09-2008 11:40 AM by chidge. 6 replies.

Sort Posts:

  • InnerHtml of Div ...

    05-09-2008, 8:32 AM
    • Loading...
    • mansoorafzal
    • Joined on 12-03-2004, 3:21 AM
    • Lahore
    • Posts 19

     hi all,

     i have a div and lots of controls within that div. values are populated at run time. now, i want to get the innerhtml of the div in code behind. how can i get that. div.InnetHtml is not working as it gives exception ("contents are not literal controls"). any work around to solve this?

    thanks in advance.
    best regards,
     

  • Re: InnerHtml of Div ...

    05-09-2008, 8:35 AM
    • Loading...
    • Curt_C
    • Joined on 07-23-2003, 8:27 PM
    • Stevens Point, WI - USA
    • Posts 3,653
    • Moderator
      TrustedFriends-MVPs

    add a runat="server" to the control.

    Then, from the codebehind it should be accessible. Depending on where the control is you may need to do a .FindControl() from the parent container, but this should get you on the right track.

  • Re: InnerHtml of Div ...

    05-09-2008, 8:38 AM
    • Loading...
    • satalaj
    • Joined on 11-28-2007, 5:41 AM
    • Pune
    • Posts 502

    Have you marked div runat = "Server"
    Can you use literal control.

    Satalaj

  • Re: InnerHtml of Div ...

    05-09-2008, 8:39 AM
    • Loading...
    • chandan.max
    • Joined on 03-28-2008, 6:37 AM
    • India
    • Posts 155

    Hi

    Use this

     in .aspx page

    <div id="divID" runat="server"></div>

     in .aspx.cs

     string str =divID.InnerHtml;

     

      
    "Mark as Answer" on the post that helped you.

    Chandan,
    Imfinity India Pte Ltd.
  • Re: InnerHtml of Div ...

    05-09-2008, 8:50 AM
    • Loading...
    • mansoorafzal
    • Joined on 12-03-2004, 3:21 AM
    • Lahore
    • Posts 19

    chandan.max:

    Hi

    Use this

     in .aspx page

    <div id="divID" runat="server"></div>

     in .aspx.cs

     string str =divID.InnerHtml;

    I have done the same. With in the opening and closing tags of DIV, i have controls like... asp:TextBox and asp:Label. now, when i try to access the DIV using:
    string s = divID.InnerHtml;

    I got the following exception:
    Cannot get inner content of divID because the contents are not literal.

    Any idea about this?

    Best Regards

  • Re: InnerHtml of Div ...

    05-09-2008, 11:28 AM
    • Loading...
    • Curt_C
    • Joined on 07-23-2003, 8:27 PM
    • Stevens Point, WI - USA
    • Posts 3,653
    • Moderator
      TrustedFriends-MVPs

    huh? Are you saying you want to read the contents of CONTROLS that are INSIDE the <div..>? If so, you just access these directly, not from the <div..>.

    You'll have to show more details.

  • Re: InnerHtml of Div ...

    05-09-2008, 11:40 AM
    • Loading...
    • chidge
    • Joined on 02-12-2008, 6:11 AM
    • Manchester, UK
    • Posts 8

    Hi,

    You can only use InnerHTML for HTML controls, wont work with ASP.NET Controls. Whats the reason for trying to access the controls, might be another solution.

Page 1 of 1 (7 items)