How do I reset all the TextBox values at once?
If you have any experience with data handling asp.net applications, then this is a very common issue for you. Even I saw few forum post in CDNUG.
With classic ASP, we have cleared all the TextBox values with simple “Reset” button. But when we come to ASP.NET we can’t apply the same.
Here, I am going to explain some tips with ASP.NET to overcome this problem.
Solution 1:
As I said earlier still you can use classic asp way to clear all the TextBox values with some conditions.
This is not ASP.NET specific way to clear all the TextBox values. Here the reset method calls the JS onreset event of HTML form object and it just reset the original value the of the TextBoxes. Because original value is empty at the first time. But we can’t use form reset method to clear TextBox values when populated data already submitted to the server. (Because original value is not empty after submitting to the server).
Solution 2:
Above code will clear all the TextBox values even submitted TextBox values also. The only problem is server postback experience and it will be worse (performance) when we have large collection of ASP.NET text boxes.
Solution 3:
When you call Server.Transfer, the page execute as a new page. I guess this is the easiest way to clear all the TextBox values. But it will not clear only TextBox values, but form collections and QueryString also...
Download source code:ClearAllTextBoxValues.zip
Labels: ASP.NET




0 Comments:
Post a Comment
<< Home