Rich Text Editing, designMode, and Javascript (again)

Discussion in 'ASP .Net' started by Erik, Oct 3, 2006.

  1. Erik

    Erik Guest

    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
    Erik, Oct 3, 2006
    #1
    1. Advertising

  2. Try adding: runat="server" to your form.

    "Erik" <> wrote in message
    news:...
    > 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
    >
    Marina Levit [MVP], Oct 3, 2006
    #2
    1. Advertising

  3. Erik

    Erik Guest

    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.
    Erik, Oct 3, 2006
    #3
  4. Erik

    Erik Guest

    Re: Rich Text Editing, designMode, and Javascript (again) SOLVED

    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.
    Erik, Oct 5, 2006
    #4
    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. Replies:
    3
    Views:
    436
  2. Martin Honnen

    Rich Text Editing

    Martin Honnen, Jan 2, 2005, in forum: Javascript
    Replies:
    1
    Views:
    82
    Börni
    Jan 2, 2005
  3. Replies:
    7
    Views:
    259
  4. mel

    rich text editing

    mel, Aug 23, 2007, in forum: Javascript
    Replies:
    3
    Views:
    97
    elephant
    Aug 24, 2007
  5. deostroll
    Replies:
    1
    Views:
    147
    deostroll
    Jan 11, 2008
Loading...

Share This Page