我很惊讶地看到昨晚我的代码工作正常,第二天突然我的textbox.text总是有空字符串..
我的代码是: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值。
为什么?
我怀疑在这里没有包含代码的情况。也许在'Page_Load'中有一些正在清除'TextBox'的东西? – David 2011-04-17 11:32:12
在你的应用程序中可能有多个表单标签webform只有一个表单标签允许检查 – 2014-07-23 20:01:12
@ImranRashid完全相同的问题毁了我的整个一天..具有runat = server属性的表单标签出现在母版页中,首先,我在代码后面得到了空值...然后我结束了两个服务器端表单标记错误! :/ – sohaiby 2015-04-26 14:41:03