retrieving DIV.innerHtml

P

Peter Wone

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?
 
K

Ken Cox [Microsoft MVP]

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>
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top