看到昨晚我的代码运行良好,第二天突然我的textbox.text始终为空字符串,我感到非常惊讶。
我的代码是:
Name of Event* :
<br />
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<br />
后面的代码:
protected void Page_Load(object sender, EventArgs e) {
}
protected void create_Click(object sender, EventArgs e) {
if (!object.Equals(Session["UserLoginId"], null)) {
int mid = 0;
int cid = 0;
bool valid = true;
if (this.TextBox1.Text == "") {
error.Text = "<p style='color:red'>Marked Fields are compulsory!!</p>";
}
else {
.... // database insert ....
}
我总是以error.text值结尾。
为什么?
最佳答案
文本框在添加新行时被清除也有类似的问题。单击添加按钮时,这是页面重新加载的问题。
通过添加以下内容解决了该问题:
Sub Page_Load
If Not IsPostBack Then
BindGrid()
End If
End Sub
根据Microsoft的文档http://msdn.microsoft.com/en-us/library/aa478966.aspx。
关于asp.net - textbox.text总是返回空字符串,而不是用户输入的文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5693236/