Click here to Skip to main content
15,922,696 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
how to clear all the field on a page on pressing refresh or backspace?
Posted

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;
          }
     }
}
 
Share this answer
 
v2
hi sanjeev,

you can find when refresh browser like this

C#
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
        }


    }

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

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900