Friday, July 21, 2006
I created a ASP.NET page with two text boxes and a button. I want this button to reset the form(Only to reset the page). There are two ways you can do this, one is going to the click event of the button and add the code to clear the text boxes. Like the one given below
protected void Button1_Click(object sender, EventArgs e)
TextBox1.Text = string.Empty;
TextBox2.Text = string.Empty;
but this technique is very heavy, bcz it need another round trip to the server.
protected void Page_Load(object sender, EventArgs e)
what this code does is that, The button is rendered like this
so that the page wiill be automatically reset when the user clicks the button (Completely handled by the browser, no round trip to the server).
The code that I bolded (return false;), its very important, other wise the page will be posted back.