检查文本框的值是否更改

发布于 2025-01-14 16:40:33 字数 60 浏览 4 评论 0原文

我在页面加载时填充了一个文本框。我想检查文本框的值是否在按“更新”按钮时更改。有什么解决办法吗? TIA。

I have a textbox filled at the page load. I want to check the value of the textbox is changed or not in the "update" button press. Any solution? TIA.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

欢你一世 2025-01-21 16:40:33

好吧,你可以说使用客户端 JavaScript。

但是,您也可以这样做:

说出这个文本框:

            <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
            <br />
            <asp:Button ID="Button1" runat="server" Text="Done - continue" OnClick="Button1_Click" />

我们的代码可以是这样的:

   protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            // code here to setup and load controls

            TextBox1.Text = "Dog";
            ViewState["TextBox1"] = "Dog";
        }
    }

    protected void Button1_Click(object sender, EventArgs e)
    {
        if (TextBox1.Text != (string)ViewState["TextBox1"])
        {
            // then text box was changed
        }
    }

Well, you could say use client side javascript.

But, you could also do this:

Say this text box:

            <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
            <br />
            <asp:Button ID="Button1" runat="server" Text="Done - continue" OnClick="Button1_Click" />

And our code could be this:

   protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            // code here to setup and load controls

            TextBox1.Text = "Dog";
            ViewState["TextBox1"] = "Dog";
        }
    }

    protected void Button1_Click(object sender, EventArgs e)
    {
        if (TextBox1.Text != (string)ViewState["TextBox1"])
        {
            // then text box was changed
        }
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文