ASP.NET:TextBox.Text不会有更新的价值 [英] ASP.NET: TextBox.Text doesn't have updated value
问题描述
我有一个初始化函数,将数据加载到我的文本框 NameTextBox
,然后我加上了s的名称。然后我点击保存按钮执行 SaveButton_Click
时NameTextBox.Text调试的值仍然是原来的串(名字),而不是(FirstNames)。为什么是这样?谢谢你。
编辑:对不起在这里你去让我知道如果你需要更多...
的Page_Load(发件人,E)
信息= GetMyInfo()
初始化()
初始化()
NameTextBox.Text = Info.Name
SaveButton_Click(发件人,E)
昏暗命令的SqlCommand命令= GetSQLCommand(StoredProcedure的)
command.Parameters.AddWithValue(@放慢参数,NameTextBox.Text)
ExecuteSQLCommand(命令)
如果文本框被禁用它不会持续回codebehind,如果你还设置初始值,每次(不管的IsPostBack的)你是实际上在写值是什么时,得到的事件处理程序(SaveButton_Click)。例如:
的Page_Load(){NameTextBox.Text =someValue中;}
....saveButton_Click(){字符串x = NameTextBox.Text;}
以上code总会有文本框的文本值是someValue中。您需要将其包装在if(!的IsPostBack)像这样....
的Page_Load(){IF {NameTextBox.Text =someValue中(的IsPostBack!);}}
....saveButton_Click(){字符串x = NameTextBox.Text;}
I have an initialize function that loads data into my textbox NameTextBox
, and then I add an "s" to the name. I then click the Save button that executes SaveButton_Click
when debugging the value for NameTextBox.Text is still the original string (FirstName) and not (FirstNames). Why is this? Thanks.
Edit: Sorry here you go let me know if you need more...
Page_Load(sender, e)
Info = GetMyInfo()
Initialize()
Initialize()
NameTextBox.Text = Info.Name
SaveButton_Click(sender, e)
Dim command As SqlCommand
command = GetSQLCommand("StoredProcedure")
command.Parameters.AddWithValue("@Paramter", NameTextBox.Text)
ExecuteSQLCommand(command)
If the textbox is disabled it will not be persisted back to the codebehind, also if you set the initial value everytime (regardless of IsPostBack) you are essentially over writing what the value is when it gets to the Event handler (SaveButton_Click). Ex:
page_load() { NameTextBox.Text = "someValue";}
....
saveButton_Click() { string x = NameTextBox.Text;}
The above code will always have the text value of the textbox be "someValue". You would need to wrap it in an if(!IsPostBack) like so....
page_load() { if(!IsPostBack) {NameTextBox.Text = "someValue";}}
....
saveButton_Click() { string x = NameTextBox.Text;}
这篇关于ASP.NET:TextBox.Text不会有更新的价值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!