使多行文本框记住文本输入(自动完成)

时间:2012-10-09 19:21:14

标签: asp.net autocomplete textbox textarea multiline

普通的asp.net文本框会记住您的旧输入 - 如果您在文本框中键入内容然后离开页面然后返回,并输入相同的内容。文本框将通过建议您上次输入的内容“自动完成”您输入的内容。

我可以看到,如果你将Textmode属性设置为“multiline”,那么文本框会丢失它的自动完成。像这样:

<asp:TextBox ID="TextBox_Description"  TextMode="MultiLine" MaxLength="500"   runat="server"></asp:TextBox>

如何将此功能添加到我的多行asp文本框或TextArea? (多行文本框呈现为textareas)。

我对asp.net特定解决方案和javascript / jquery解决方案都持开放态度。

1 个答案:

答案 0 :(得分:0)

您可以检索多行文本框中的内容然后对其进行缓存,并在回发时使用缓存来输出之前使用过的内容。

// Get everything in the multiline text box and cache it
Cache["multilineValues"] = TextBox_Description.Text;

// Output what was written again through cache etc when the page loads after a postback. 
//You would most likely put this in the Page_Load method.
if(IsPostBack)
{
    if(Cache["multilineValues"] != null)
    {
      //Use what was written before
      TextBox_Description.Text = (string)Cache["multilineValues"];
    }
}