在ascx中使用UpdatePanel时丢失TextBox值?

时间:2012-03-26 09:36:59

标签: c# asp.net updatepanel

我在一个更新面板中有2个更新面板我有一个数据列表,在其他更新面板中我有一个带有tinymce编辑器的文本框。

<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
<ContentTemplate>
 <asp:DataList ID="dlst1" runat="server" RepeatDirection="Horizontal" CellSpacing="5" CellPadding="7" 
     DataKeyField="Id" CaptionAlign="Left" OnItemCommand="dls1_ItemCommand"                        
     OnItemDataBound="dlst1_ItemDataBound">
   <ItemTemplate>
     <asp:ImageButton ID="btnImg" OnClientClick="javascript:void(0);" 
       runat="server" ImageUrl='<%#"~/Controls/Images.ashx?FileName=" +DataBinder.Eval(Container.DataItem, "FilePath") %>' 
       CommandName="Select" OnCommand="Select_Command" 
        CommandArgument='<%# Eval("Id").ToString() ' />   
   </ItemTemplate>
</asp:DataList>
</ContentTemplate>

<asp:UpdatePanel ID="UpdatePanel2" runat="server" UpdateMode="Always">
<ContentTemplate>
   <asp:TextBox ID="TextBox1" CssClass="tinyEditor" ClientIDMode="Static" runat="server" TextMode="MultiLine"></asp:TextBox>
</ContentTemplate>
</asp:UpdatePanel>

使tinymce工作我正在使用

ScriptManager.RegisterClientScriptBlock(UpdatePanel2, this.GetType(), "init", "tinyMCE.execCommand('mceAddControl', false, '" + TextBox1.ClientID + "');", true);

var prm = Sys.WebForms.PageRequestManager.getInstance();
prm.add_endRequest(function () {
TinyMCEEditor();
});

$(function () {
TinyMCEEditor();
});

我的TinyMCE编辑器

 function TinyMCEEditor() {
tinyMCE.init({
    mode: "textareas",
    theme: "advanced"
});
}
页面加载

我正在为每个图像提供文本,对于上一个图像,我将文本框值存储在视图状态中,假设我有3个图像用于图像1我已经给出了文本abcd和所选图像2,因此图像1文本将存储在viewstate中。

在Select_Command上:

 if (ViewState["txbtext"] != null)
            txbtext= (Hashtable)ViewState["txbtext"];
        int index1 = previouslySelectedIndex;
        if (index1 != -1)
        {
            ImageButton imgbtn= (dlst1.Items[index1].FindControl("btnImg") as ImageButton);
            if (imgbtn!= null)
            {
                string[] ImgStr = imgbtn.CommandArgument.ToString().Split(';');
                Int32 selectedId = Convert.ToInt32(Str[0]);
                if (txbtext!= null && txbtext.ContainsKey(selectedId))
                    txbtext[selectedId] = textbox.Text;
                else
                    txbtext.Add(selectedId, textbox.Text);
            }
        }
        ViewState["txbtext"] = txbtext (//this is the hashtable);
      }

当我没有使用更新面板时,它工作正常,但是当我使用更新面板时,我无法将文本框值存储在viewstate中,

请有人告诉我如何解决此问题,如果可能的话,请给出一些exp。代码。

有一个人帮助我

2 个答案:

答案 0 :(得分:0)

我遇到了同样的问题,我决定使用另一个编辑器。看看CKEditor for ASP.NET http://www.ckeditor.com/download

答案 1 :(得分:0)

我添加了

onchange_callback: function(ed) { ed.save(); }

我的TInyMCE编辑器现在正在工作......