retrieving DIV.innerHtml

Discussion in 'ASP .Net Web Controls' started by Peter Wone, Mar 1, 2005.

  1. Peter Wone

    Peter Wone Guest

    I created a WebUserControl that renders <DIV CONTENTEDITABLE
    ID="whatever"></DIV> to offer HTML editing in a web page.

    On postback I don't get the content of the DIV. This is unsurprising; it's
    not an INPUT control. When I doing this in classic ASP I used to hook the
    form's onsubmit event with some javascript to harvest the DIV tag innerHtml
    into an INPUT TYPE="HIDDEN" field.

    I -could- embed some inline script to add another handler to the onsubmit
    event of the form containing the control. What's the -recommended- way to go
    about implementing this sort of thing with an ASP.NET WebUserControl?
    Peter Wone, Mar 1, 2005
    #1
    1. Advertising

  2. Hi Peter,

    I'd do this about the same way you suggested except using the Panel control
    which renders as a div. You could store the innerHTML in a hidden textbox
    the way you were doing and still catch the text on the server-side. Here's a
    sample of what I was playing with. Let us know if it helps?

    Ken
    Microsoft MVP [ASP.NET]
    Toronto


    Private Sub Page_Load _
    (ByVal sender As System.Object, _
    ByVal e As System.EventArgs) Handles MyBase.Load
    Panel1.Attributes.Add("CONTENTEDITABLE", "true")
    Button1.Attributes.Add("onclick", _
    "document.all.item('TextBox1').value=document.all.Panel1.innerHTML;")
    End Sub

    Private Sub Button1_Click _
    (ByVal sender As System.Object, _
    ByVal e As System.EventArgs) Handles Button1.Click
    Label1.Text = TextBox1.Value
    End Sub

    <form id="Form1" method="post" runat="server">
    <asp:panel id="Panel1" runat="server">Panel</asp:panel>
    <p><input id="TextBox1" name="TextBox1" type="hidden"
    runat="server"></p>
    <p>
    <asp:button id="Button1" runat="server"
    Text="Button"></asp:button></p>
    <p>
    <asp:label id="Label1" runat="server"></asp:label></p>
    </form>


    "Peter Wone" <> wrote in message
    news:uX%...
    >I created a WebUserControl that renders <DIV CONTENTEDITABLE
    >ID="whatever"></DIV> to offer HTML editing in a web page.
    >
    > On postback I don't get the content of the DIV. This is unsurprising; it's
    > not an INPUT control. When I doing this in classic ASP I used to hook the
    > form's onsubmit event with some javascript to harvest the DIV tag
    > innerHtml into an INPUT TYPE="HIDDEN" field.
    >
    > I -could- embed some inline script to add another handler to the onsubmit
    > event of the form containing the control. What's the -recommended- way to
    > go about implementing this sort of thing with an ASP.NET WebUserControl?
    >
    Ken Cox [Microsoft MVP], Mar 1, 2005
    #2
    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. yer darn tootin
    Replies:
    2
    Views:
    712
    yer darn tootin
    Jun 8, 2005
  2. K Viltersten

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

    K Viltersten, Mar 30, 2009, in forum: ASP .Net
    Replies:
    4
    Views:
    724
  3. Dwayne Madsen

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

    Dwayne Madsen, Jun 1, 2005, in forum: Javascript
    Replies:
    1
    Views:
    176
    David Dorward
    Jun 1, 2005
  4. mscir
    Replies:
    3
    Views:
    296
    Martin Honnen
    Jun 26, 2005
  5. sonic
    Replies:
    5
    Views:
    267
    Randy Webb
    Jul 11, 2006
Loading...

Share This Page