ASP.NET - 文本框的文本并不在code变化背后 [英] ASP.NET - Text of TextBox does not change in code behind
问题描述
所以我在我的网站一个文本框:
so I have a textbox on my website:
<asp:TextBox ID="Latitude" runat="server" ClientIDMode="Static" ></asp:TextBox>
和在页面加载我填补这一文本从一个DATABSE东西:
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;
}
但是,当我想更新我与该文本框的新值DATABSE,它仍然更新了一个摆在页面加载数据库:
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);
}
这是正常的吗?我怎样才能确保我setCoordinates()得到文本框中的新的价值,而不是看跌的文本与Latitude.Text = thisPlace.Latitude; ?
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; ?
推荐答案
我认为它是因为回传
如果你调用setCoordinates()上的一些按钮的Click事件的文本框的新值将会丢失。如果这是正确的变化的Page_Load像这样的
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;
}
}
这篇关于ASP.NET - 文本框的文本并不在code变化背后的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!