Rich Text Editing, designMode, and Javascript (again)

E

Erik

I've found several posts discussing this, but I'm still stumped.

Pasted below is the HTML for a simple aspx file I created in a 1.1
environment. My goal is to give my users a rich text editor, and then
have the HTML submitted to the code behind as a form variable so I can
manipulate it any way I want. The page renders correctly, and the user
can type in the iFrame. And I've determined (via calls to alert())
that setBody() is being called and values are set correctly. But on
the back end I'm consistantly not getting any of the text in the
iframe. I've even written versions that were Netscape friendly, and
had the exact same results.

Any ideas? If I could get this to work it would solve a big problem
for me.

iframeTest.aspx:

<%@ Page Language="vb" AutoEventWireup="false"
Codebehind="iFrameTest.aspx.vb" Inherits="iFrameTest"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>iFrameTest</title>

<script>
function setEditor(md) {
// document.editorFrame.document.body.innerHTML = "<b>This is a
test</b> really.";
document.editorFrame.document.designMode=md;
}

function setBody() {

var msgTxt, bdy;

msgTxt = document.editorFrame.document.body.innerHTML;
bdy = document.getElementById("messageBody");
bdy.Value = msgTxt;

return true;
}

</script>

</head>
<body onLoad="setEditor('On');">

<form id="Form1" method="post" onsubmit="return setBody();">
<iframe class="bodyBox" name="editorFrame" id="editorFrame">
</iframe>
<input type="hidden" name="messageBody"/>
<input type="submit">
</form>

</body>
</html>

iframeTest.aspx.vb:

Public Class iFrameTest
Inherits System.Web.UI.Page

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

If Not Request.Form("messageBody") Is Nothing Then

If Request.Form("messageBody").Length > 0 Then
Response.Write("got a value!")
Else
Response.Write("still nothing")
End If

End If

End Sub

End Class
 
E

Erik

Marina said:
Try adding: runat="server" to your form.

Makes no difference. The example I posted doesn't have any server
rendered controls anyway, so the only difference adding runat="server"
to the form is the server automatically inserts the hidden form
variable "__VIEWSTATE".

I tried making the form using server controls (changing the <input
type="submit"> to <asp:Button ...> and so on) and got the same results.
 
E

Erik

Tacky to repond to my own post, but: I figured out what the problem
was. My test file had the following bit of Javascript:
...
msgTxt = document.editorFrame.document.body.innerHTML;
bdy = document.getElementById("messageBody");
bdy.Value = msgTxt;
...

The problem turned out to be "bdy.Value". Javascript is case
sensitive, and the attribute is properly accessed as "bdy.value". See
the difference?

Made that change and the page worked exactly as expected. Boy do I
feel foolish.
 

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,818
Messages
2,569,727
Members
45,664
Latest member
Phil79581

Latest Threads

Top