93 可读性
 将光标移到/点击文章中的句子上,可以查看译文。      显示繁体中文内容    显示简体中文内容

c# - Text of TextBox does not change in code behind
在代码 behind 中,文本框的C# 文本不更改

113 5

so i have a textbox on my website :

<asp:TextBox ID="Latitude" runat="server" ClientIDMode="Static"> </asp:TextBox>

and on page load i fill that textbox with something from a databse :

protected void Page_Load(object sender, EventArgs e)
{
 Latitude.Text = thisPlace.Latitude;
}

But when i want to update my databse with a new value in that textbox, it still updated the database with the one put in on page load :

protected void Save_Click(object sender, EventArgs e)
{
 setCoordinates(Latitude.Text);
}

Is this normal? how can i make sure that i in setCoordinates() get the new value from the textbox and not the one put in the textbox with Latitude.Text = thisPlace.Latitude;?

时间:原作者:0个回答

128 4

I think its because PostBack

If you're calling setCoordinates() on some button's click event textbox's new value will be lost.if that's right change Page_Load like this one

protected void Page_Load(object sender, EventArgs e)
{
 if(!IsPostBack)
 {
 Latitude.Text = thisPlace.Latitude;
 } 
}
原作者:
...