locked
HtmlEditorExtender loses its text during postback RRS feed

  • Question

  • User1386957622 posted

    Hi,
    In my project , When I type texts in the HtmlEditorExtender, and click on a button. Everything works fine. But when I copy & Paste texts (short , a word ,paragraphs etc). The HtmlEditorExtender loses its data. 

    my code looks like this: Default.aspx

    <asp:UpdatePanel runat="server" ID="id123">
    <Triggers>
    <asp:PostBackTrigger ControlID="Button1" />
    </Triggers>
    <ContentTemplate>
    
    <asp:TextBox ID="txtSlidePage"  TextMode="MultiLine" Columns="50" Rows="10" Width="100%" Height="200" runat="server" />
    
    <ajaxToolkit:HtmlEditorExtender ID="HtmlEditorExtender1" TargetControlID="txtSlidePage"   runat="server" DisplaySourceTab="true">
    <Toolbar>
    <ajaxToolkit:Undo />
    <ajaxToolkit:Redo />
    </Toolbar>
    </ajaxToolkit:HtmlEditorExtender>
    
    </ContentTemplate>
    </asp:UpdatePanel>
    <asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click1"  />

    Default.aspx.cs:

     protected void Button1_Click1(object sender, EventArgs e)
        {
    
            Response.Write("<script>alert('" + txtSlidePage.Text + "');</script>");
        }


    Any Ideas about this issue?

    Wednesday, April 6, 2016 6:44 PM

Answers

  • User61956409 posted

    Hi rebo,

    I create the following sample to reproduce the issue on my side, I could get the text that I copy from txt file and paste in HtmlEditorExtender.

    <asp:UpdatePanel ID="UpdatePanel1" runat="server">
        <ContentTemplate>
            <asp:TextBox ID="txtDescription" runat="server" Width="500" Height="300"></asp:TextBox>
            <asp:HtmlEditorExtender ID="HtmlEditorExtender1" runat="server" TargetControlID="txtDescription" EnableSanitization="false" DisplaySourceTab="true">
                <Toolbar>
                    <asp:Italic />
                    <asp:Underline />
                    <asp:StrikeThrough />
                    <asp:Subscript />
                    <asp:Superscript />
                    <asp:JustifyLeft />
                    <asp:JustifyCenter />
                    <asp:JustifyRight />
                    <asp:JustifyFull />
                    <asp:InsertOrderedList />
                    <asp:InsertUnorderedList />
                    <asp:CreateLink />
                    <asp:UnLink />
                    <asp:RemoveFormat />
                    <asp:Cut />
                    <asp:Copy />
                    <asp:Paste />
                    <asp:BackgroundColorSelector />
                    <asp:ForeColorSelector />
                    <asp:FontNameSelector />
                    <asp:FontSizeSelector />
                    <asp:Indent />
                    <asp:Outdent />
                    <asp:InsertHorizontalRule />
                    <asp:HorizontalSeparator />
                    <asp:InsertImage />
                </Toolbar>
            </asp:HtmlEditorExtender>
        </ContentTemplate>
        <Triggers>
            <asp:PostBackTrigger ControlID="Button1" />
        </Triggers>
    </asp:UpdatePanel>
    <asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />
    
    protected void Button1_Click(object sender, EventArgs e)
    {
        Response.Write("<script>alert('" + txtDescription.Text + "');</script>");
    }
    

    Best Regards,

    Fei Han



    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, April 7, 2016 3:22 AM

All replies

  • User-359936451 posted

    Your click Event is reloading the page and writing over your values. You need a check in the From Load Event to get around this.

        Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
            If Not IsPostBack Then
                Label999.Visible = False
                Label2.Visible = True
    Label2.Text = "not a Postback"
    Else
    Label2.Text = "IS a Postback"
    End If End Sub

    Wednesday, April 6, 2016 8:05 PM
  • User61956409 posted

    Hi rebo,

    I create the following sample to reproduce the issue on my side, I could get the text that I copy from txt file and paste in HtmlEditorExtender.

    <asp:UpdatePanel ID="UpdatePanel1" runat="server">
        <ContentTemplate>
            <asp:TextBox ID="txtDescription" runat="server" Width="500" Height="300"></asp:TextBox>
            <asp:HtmlEditorExtender ID="HtmlEditorExtender1" runat="server" TargetControlID="txtDescription" EnableSanitization="false" DisplaySourceTab="true">
                <Toolbar>
                    <asp:Italic />
                    <asp:Underline />
                    <asp:StrikeThrough />
                    <asp:Subscript />
                    <asp:Superscript />
                    <asp:JustifyLeft />
                    <asp:JustifyCenter />
                    <asp:JustifyRight />
                    <asp:JustifyFull />
                    <asp:InsertOrderedList />
                    <asp:InsertUnorderedList />
                    <asp:CreateLink />
                    <asp:UnLink />
                    <asp:RemoveFormat />
                    <asp:Cut />
                    <asp:Copy />
                    <asp:Paste />
                    <asp:BackgroundColorSelector />
                    <asp:ForeColorSelector />
                    <asp:FontNameSelector />
                    <asp:FontSizeSelector />
                    <asp:Indent />
                    <asp:Outdent />
                    <asp:InsertHorizontalRule />
                    <asp:HorizontalSeparator />
                    <asp:InsertImage />
                </Toolbar>
            </asp:HtmlEditorExtender>
        </ContentTemplate>
        <Triggers>
            <asp:PostBackTrigger ControlID="Button1" />
        </Triggers>
    </asp:UpdatePanel>
    <asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />
    
    protected void Button1_Click(object sender, EventArgs e)
    {
        Response.Write("<script>alert('" + txtDescription.Text + "');</script>");
    }
    

    Best Regards,

    Fei Han



    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, April 7, 2016 3:22 AM
  • User1386957622 posted

    Hi Fei Han,
    Thank you for your post. Yes it solved the issue. 

    Thursday, April 7, 2016 6:29 AM