4

我的 ASP.NET 页面上有一个 TinyMCE 脚本,借助该功能SaveFAQ(),我们可以保存 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");
    }
}

我第一次按下保存按钮时,它会触发一个执行此功能的事件SaveFAQ();。它成功地在数据库中创建了一行,但字符串mceQuestion.Value&mceAnswer.Value为空。我第二次按下按钮时,它会触发完全相同的事件,并且值已填充并成功保存。

我该怎么做才能只按一次保存?

感谢所有答案,祝您有美好的一天!

编辑: 这是 mceQuestion;

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

编辑2: 一直试图将这种节省与新闻的保存(完全有效)进行比较。没有大的差异,我一直在测试这方面的差异,SaveFAQ()但这并没有减少它。

这是我的 TinyMCE 设置,如果它们可能派上用场的话。

<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>

我感谢任何可能或确实引导我走向正确方向的反馈、答案或提示!

4

1 回答 1

6

OnClientClick="tinyMCE.triggerSave(false,true);"我通过添加到每个保存按钮来修复它。

于 2013-07-03T09:31:02.347 回答