为什么我的保存使用TextBox的初始值而不是输入的值? [英] Why does my save use the initial value of my TextBox and not the entered value?

查看:112
本文介绍了为什么我的保存使用TextBox的初始值而不是输入的值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的网站上有一个文本框:

I have a textbox on my website:

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

在页面加载时,我用数据库中的内容填充该文本框:

On page load I fill that textbox with something from a databse:

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

当我想用该文本框中的新值更新我的数据库时,它仍然使用放在页面加载的数据库更新数据库:

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;

How can I make sure that setCoordinates() retrieves the new value from the textbox and not the initial value from the database from Latitude.Text = thisPlace.Latitude;?

推荐答案

我认为是因为 PostBack

如果您正在呼叫 setCoordinates()在某个按钮的点击事件文本框中,新值将丢失。如果正确改变 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;
    }    
}

这篇关于为什么我的保存使用TextBox的初始值而不是输入的值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆