gpt4 book ai didi

asp.net - textbox.text总是返回空字符串,而不是用户输入的文本

转载 作者:行者123 更新时间:2023-12-04 03:46:10 24 4
gpt4 key购买 nike

看到昨晚我的代码运行良好,第二天突然我的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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com