按刷新或退格键清除页面上的所有字段 [英] clear all the field on a page on pressing refresh or backspace

查看:77
本文介绍了按刷新或退格键清除页面上的所有字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在按下刷新或退格键时清除页面上的所有字段?

how to clear all the field on a page on pressing refresh or backspace?

推荐答案

创建一个方法并在刷新按钮上调用.

这样....

Create One Method and Call at refresh button.

like that....

public void ClearAll(form frm)
{
     foreach(Control ctl in frm.Controls)
     {
        if(ctl is Textbox)
          {
             ctl.text="";
          }
        if(ctl is checkBox)
          {
            ctl.selectedIndex=0;
          }
     }
}


嗨桑耶夫,

您可以找到何时刷新这样的浏览器

hi sanjeev,

you can find when refresh browser like this

protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            Session["CheckRefresh"] = Server.UrlDecode(System.DateTime.Now.ToString());
        }
if (Session["CheckRefresh"].ToString() == ViewState["CheckRefresh"].ToString())
        {
            Label1.Text = "Hello";
            Session["CheckRefresh"] = Server.UrlDecode(System.DateTime.Now.ToString());
        }
        else
        {
            Label1.Text = "Page Refreshed";
            string str = "your code will save here or call save() method here";
//and here you can call clearallfields() method
        }


    }


protected void Page_PreRender(object sender, EventArgs e)
    {
        ViewState["CheckRefresh"] = Session["CheckRefresh"];
    }


这篇关于按刷新或退格键清除页面上的所有字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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