回发后清除文本框 [英] clear textbox after postback

查看:69
本文介绍了回发后清除文本框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在ascx页面上有一个文本框和一个按钮.

I have a textbox and a button on the ascx page.

输入文本后,我单击将发布到数据库并清除文本框的按钮.

After entering text i click on the button where it will post to the database and clear the textbox.

放置后,如果我刷新网页,它将转到按钮单击方法,并将旧文本发布到数据库中.我如何从视图状态清除文本框值.

After positing, if i refresh the web page it is going to the button click method and posting the old text to the database. how can i clear the textbox value from the view state.

我已将文本框的enableviewstate设置为false.但是仍然无法正常工作.请告诉我.谢谢

i have set the enableviewstate of the textbox to false. But still it is not working. Please let me know. Thanks

推荐答案

protected void btnClear_Click(object sender, EventArgs e)
    {
        ClearControls();

    }
    private void ClearControls()
    {
        foreach (Control c in Page.Controls)
        {
            foreach (Control ctrl in c.Controls)
            {
                if (ctrl is TextBox)
                {
                    ((TextBox)ctrl).Text = string.Empty;
                }
            }
        }
    }

这篇关于回发后清除文本框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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