2012-10-09 94 views
0

正常的asp.net文本框会记住您的旧输入 - 如果您在文本框中输入某些内容并离开该页面然后返回,并输入相同的内容。该文本框会通过建议你上次输入的内容来“自动完成”你正在输入的内容。使多行文本框记住文本输入(自动完成)

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

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

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

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

+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"]; 
    } 
}