TinyMCE doesnt return any value the first time I'm saving

asp.net, events, function, save, tinymce

Solution

I fixed it by adding `OnClientClick="tinyMCE.triggerSave(false,true);"` to each saving-button.

Problem

I have a TinyMCE script on my ASP.NET page and with help of the function `SaveFAQ()` we can save the textarea(s) that the TineMCE uses. ``` 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 I press the save-button it triggers a event which executes this function `SaveFAQ();`. It successfully creates a row in the database and such but the strings `mceQuestion.Value` & `mceAnswer.Value` are empty. The second time I press the button it triggers the exact same event and the values are filled and it saves successfully. How can I do so that I just have to press save once? Appreciate all answers, have a great day! EDIT: Here is mceQuestion; ``` <textarea ID="mceQuestion" runat="server" cols="100" rows="6" /> ``` EDIT 2: Been trying to compare this saving with the saving of the news (which are fully working). There are no big differences and I've been testing out the differences on this `SaveFAQ()` but that does not cut it. Here are my TinyMCE settings if they might 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 which might or does lead me in the right direction!

Original source