By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,357 Members | 1,021 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,357 IT Pros & Developers. It's quick & easy.

Rich Text Editing, designMode, and Javascript (again)

P: n/a
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</breally.";
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

Oct 3 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Try adding: runat="server" to your form.

"Erik" <ea****@sheppardmullin.comwrote in message
news:11**********************@b28g2000cwb.googlegr oups.com...
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</breally.";
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

Oct 3 '06 #2

P: n/a
Marina Levit [MVP] wrote:
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.

Oct 3 '06 #3

P: n/a
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.

Oct 5 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.