我有一个用户控件,它有一个gridview,按钮和一个多行文本框用于注释。为什么多线文本框(在用户控件中)在回发后没有保留其值?
当页面回发时,Gridview是正常行为(其控件在回发后保留其值)。但是,无论我做什么,评论文本框始终是空的。
protected void Page_Load(object sender, EventArgs e)
{
//This code is in the user ciontrol.
if (!IsPostBack)
{
string test = this.txtDepartmentComments.Text;
}
}
我在该行放置了一个断点,该值总是空的。我也试着设置代码后面的值,如:
protected void Page_Load(object sender, EventArgs e)
{
//This code is in the user ciontrol.
if (!IsPostBack)
{
this.txtDepartmentComments.Text = "Test!";
}
}
但是当页面加载时,控件仍为空。
任何想法,为什么这是头痛?
编辑
这个ascx的代码(即用户控件)
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns = "false" >
</asp:GridView>
<asp:TextBox ID="txtComments" runat="server" Columns="45" TextMode= "MultiLine"/>
<asp:Button ID="btnComplete" runat="server" Text="Completed"/>
而且THID ID的ASPX(即父页)
<asp:Repeater ID="rpNewHire" runat="server">
<HeaderTemplate>
<table>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td>
<user:MyUserControl ID = "MyUserControl1" runat = "server"
DepartmentID= '<%# Eval("DepID")%>'><user:MyUserControl />
</td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
如果(!IsPostback)已添加/删除,但结果保持不变。 – Richard77 2013-02-14 20:48:18