Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Rich Text Editing, designMode, and Javascript (again)

Reply
Thread Tools

Rich Text Editing, designMode, and Javascript (again)

 
 
Erik
Guest
Posts: n/a
 
      10-03-2006
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

 
Reply With Quote
 
 
 
 
Marina Levit [MVP]
Guest
Posts: n/a
 
      10-03-2006
Try adding: runat="server" to your form.

"Erik" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) 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</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
>



 
Reply With Quote
 
 
 
 
Erik
Guest
Posts: n/a
 
      10-03-2006
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.

 
Reply With Quote
 
Erik
Guest
Posts: n/a
 
      10-05-2006
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.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
rich:dataTable - rich:dataScroller Hollow Quincy Java 5 01-02-2012 08:59 PM
Firefox - Rich Text Editing: Cannot do a text bold...? deostroll Javascript 1 01-11-2008 09:49 PM
Plain Text & Rich Text Formats Not Behaving: Thoughts On ? Robert11 Computer Support 9 11-28-2005 10:29 PM
Rich Text Form in JavaScript gives error: Object required IkBenHet Javascript 1 07-07-2005 10:46 AM
Content from a memo field: converting the rich text into plain text Alfredo Agosti ASP General 3 09-19-2003 05:01 PM



Advertisments