TinyMCE does not return any value on first save

I have a TinyMCE script in my ASP.NET page, and with the SaveFAQ() function we can save the text fields used by TineMCE.

 private void SaveFAQ(bool returnToFAQ = false) { DataSet ds = new DataSet(); if (mceQuestion.Value.Length > 7) if (mceQuestion.Value.Substring(0, 3) == "<p>" && "</p>" == mceQuestion.Value.Substring(mceQuestion.Value.Length - 4, 4)) { mceQuestion.Value = mceQuestion.Value.Substring(3, mceQuestion.Value.Length - 7); } DateTime? faqFromDate; DateTime tmp; if (DateTime.TryParse(txtQuestionOfTheDay.Text, out tmp)) faqFromDate = tmp; else faqFromDate = null; ds = _server.AdminSaveFAQ(FAQ_Id, chbHighlight.Checked, LAN_Id_Primary, mceQuestion.Value, mceAnswer.Value, txtFlash.Text, mceStepByStep.Value, mceTip.Value, faqFromDate, chbImportant.Checked); if (FAQ_Id == 0) FAQ_Id = (int)ds.Tables[0].Rows[0]["FAQ_Id"]; foreach (Control c in pnlCheckbox.Controls) { if (c.GetType() == typeof(CheckBox)) _server.AdminSaveFAQCategory(FAQ_Id, int.Parse(((CheckBox)c).ID), ((CheckBox)c).Checked); } if (!returnToFAQ) { lblStatusUp.Visible = true; lblStatusDown.Visible = true; if (!ds.DataSetEmpty()) { lblStatusUp.Text = "Saved successfully!"; lblStatusDown.Text = "Saved successfully!"; lblStatusUp.ForeColor = System.Drawing.Color.Green; lblStatusDown.ForeColor = System.Drawing.Color.Green; } else { lblStatusDown.Text = "Error while saving!"; lblStatusUp.Text = "Error while saving!"; lblStatusUp.ForeColor = System.Drawing.Color.Red; lblStatusDown.ForeColor = System.Drawing.Color.Red; } } else { //if (Session["PreviousPage"] != null) Response.Redirect(Session["PreviousPage"].ToString()); Response.Redirect("~/Administration/FAQ.aspx"); } } 

The first time you press the save button, an event is triggered that performs this function SaveFAQ(); . It successfully creates a row in the database and such, but the rows mceQuestion.Value and mceAnswer.Value are empty. The second time I press the button, it triggers the same event, and the values ​​are populated and successfully saved.

How can I make it easy to click "Save" once?

Appreciate all the answers, get a great day!

EDIT: Here's mceQuestion;

 <textarea ID="mceQuestion" runat="server" cols="100" rows="6" /> 

EDIT 2: Tried to compare this savings with saving news (which fully work). There are no big differences, and I tested the differences in this SaveFAQ() , but that does not shorten it.

Here are my TinyMCE settings if they can come in handy.

 <script type="text/javascript"> tinyMCE.init({ // General options mode: "textareas", theme: "advanced", plugins: "autolink,lists,spellchecker,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template", // Theme options theme_advanced_buttons1: ",bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,|,styleselect,formatselect,fontselect,fontsizeselect", theme_advanced_buttons2: "cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,cleanup,help,code,|,insertdate,inserttime,preview,|,forecolor,backcolor", theme_advanced_buttons3: "tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,|,charmap,emotions,iespell,media,advhr,|,print,|,ltr,rtl,|,fullscreen", theme_advanced_buttons4: "insertlayer,moveforward,movebackward,absolute,|,styleprops,spellchecker,|,cite,abbr,acronym,del,ins,attribs,|,visualchars,nonbreaking,template,blockquote,pagebreak,|,insertfile,insertimage", theme_advanced_toolbar_location: "top", theme_advanced_toolbar_align: "left", theme_advanced_statusbar_location: "bottom", theme_advanced_resizing: true, // Skin options skin: "o2k7", skin_variant: "silver", // Example content CSS (should be your site CSS) //content_css: "css/example.css", // Drop lists for link/image/media/template dialogs template_external_list_url: "js/template_list.js", external_link_list_url: "js/link_list.js", external_image_list_url: "Images.aspx", media_external_list_url: "js/media_list.js", // Replace values for the template plugin //template_replace_values: { // username: "Some User", // staffid: "991234" //} }); </script> 

I appreciate any feedback, answers or tips that can lead me in the right direction!

+4
source share
1 answer

I installed it by adding OnClientClick="tinyMCE.triggerSave(false,true);" to each save button.

+5
source

Source: https://habr.com/ru/post/1489040/


All Articles