locked
Can not Retrieve Value from TinyMCE Asp Textbox RRS feed

  • Question

  • User1228272764 posted

    I have a problem when my submit button fired, somehow my textbox value did not have the new value. This event happens in update data with TinyMCE Textbox. 

    Here is my aspx code : 

    <%@ Page Title=""  Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true"   CodeFile="Edit_Lowongan.aspx.cs" Inherits="PagesHRD_Edit_Lowongan" ValidateRequest="false"%>
    
    <asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
    </asp:Content>
    <asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
        <script type="text/javascript" src="https://tinymce.cachefly.net/4.0/tinymce.min.js"></script>
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
        <script type="text/javascript">
            tinymce.init({
                //encoding: 'xml' ,
                selector: ".mcetiny",
                theme: "modern",
                plugins: [
                 " autolink lists link  charmap  preview hr anchor pagebreak",
                 "searchreplace wordcount visualblocks visualchars code fullscreen",
                 "insertdatetime  nonbreaking save  contextmenu directionality",
                 "emoticons template paste textcolor"
                ],
                toolbar1: " undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify |  numlist outdent indent |  ", //bullist
                toolbar2: "print preview  | forecolor backcolor emoticons",
                image_advtab: true,
                templates: [
                    { title: 'Test template 1', content: 'Test 1' },
                    { title: 'Test template 2', content: 'Test 2' }
                ]
            });
    </script> 
        <script type="text/javascript">
            $(document).ready(function () {
                //just for testing, if i call trigger save first then btn click asp
                $("p").click(function () {
                    tinymce.triggerSave();
                    document.getElementById('<%= btnSubmit.ClientID %>').click()
                });
            });
    </script>
        <div >
            <div class="form-group">
                <div class="col-sm-8" style="margin-bottom:4%;margin-top:1%">
                    <h2 class="display-4">Form Edit Lowongan Pekerjaan</h2>
                </div>
            </div>
            <div class="form-group">
                <div class="col-sm-8"> 
                    <asp:Label ID="Label4" runat="server" Text="Tanggal Posting : " Font-Bold="true"></asp:Label><br />
                    <asp:TextBox ID="TxtTglPosting" ReadOnly="true" class="form-control" runat="server" Width="200px"></asp:TextBox>
                </div>
             </div>     
            <div class="form-group">
                <div class="col-sm-8"> 
                    <asp:Label ID="Label5" runat="server" Text="Posisi : " Font-Bold="true"></asp:Label><br />
                   <asp:TextBox ID="TxtPosisi" class="form-control" runat="server" Width="300px" AutoComplete="off"></asp:TextBox>
                </div>
             </div>  
            <div class="form-group">
                <div class="col-sm-8"> 
                    <asp:Label ID="Label6" runat="server" Text="Kualifikasi : " Font-Bold="true"></asp:Label><br />
                    <asp:TextBox ID="tbxTinymce" CssClass="mcetiny" runat="server"></asp:TextBox>
                    <asp:TextBox ID="TextBox1" CssClass="mcetiny" runat="server"></asp:TextBox>
                </div>
             </div>     
            <div class="form-group">
                <div class="col-sm-8"> 
                    <br />
                    <asp:Button ID="btnSubmit" class="btn btn-danger"  runat="server" Text="Simpan Data" OnClick="Submit"/>
                    <p>Click on this paragraph.</p>
                </div>
             </div>    
        </div>
    </asp:Content>
    
    

    i am not add any server code side . just typical update function.

            posisi = TxtPosisi.Text;
            kualifikasi = Convert.ToString(tbxTinymce.Text);
            query_updateLowongan = "update List_Lowongan set Posisi = '"+posisi+ "', Kualifikasi = '"+ kualifikasi + "' where id_lowongan = "+id+"";
            //query_insert_lowongan = "Insert into List_Lowongan (Posisi,Kualifikasi,Status_Lowongan)values ('" + TxtPosisi.Text + "','" + tbxTinymce.Text + "',1)";
            var insert = cn.KelasKoneksi_Insert(query_updateLowongan);
            if (insert == "1")
            {
                ShowAlertAndNavigate("Berhasil Memperbarui Data Lowongan", "HomeHRD.aspx?Menu=1");
            }
            else
            {
                ShowAlertAndNavigate("Gagal Memperbarui Data Lowongan", "HomeHRD.aspx?Menu=1");
            }

    do you find any suspicious things that make this update step didn't work?

    Friday, July 12, 2019 2:39 AM

All replies

  • User665608656 posted

    Hi tandasanyu,

     posisi = TxtPosisi.Text;
     kualifikasi = Convert.ToString(tbxTinymce.Text);

    According to your description, is there an error warning in your code?

    If not, is it after the update operation that the database table updates only the other fields, but not the Kualifikasi field?

    I recommend that you break a point next to the code executed in the code behind.

    When you enter a value, trigger the code behind event and check step by step through F10 to see if you have successfully obtained the value of tbxTinymce.

    If you still can't solve this issue, I suggest you give us the detailed code of update for reference.

    I hope this will help you.

    Best Regards,

    YongQing.

    Friday, July 12, 2019 6:10 AM
  • User1228272764 posted

    This is the error that I got from the update code : 

    A potentially dangerous Request.Form value was detected from the client (ctl00$ContentPlaceHolder1$tbxTinymce="<p>Kualifikasi :&nbs...").

    and solved by adding this : 

     ValidateRequest="false"
    <httpRuntime requestValidationMode="2.0"/>

    but then still, the textbox TinyMCE cannot give its value. Submit button always get the value of page load. not the new one 

    Friday, July 12, 2019 6:21 AM
  • User665608656 posted

    Hi tandasanyu,

    I have configured the settings as you do, and give TinyMCE a value when pageLoad.

    After modification, trigger the click event to successfully get the latest value of TinyMCE.

    I hope you can provide all the relevant code on your page, because I can't figure out the reason for the error from these information.

    Best Regards,

    YongQing.

    Friday, July 12, 2019 8:50 AM