Wednesday, January 20, 2010

How to clear containts all controls in asp.net?

I want to clear all the data entered by user at the time of post back.


Is there any special command to clear all the containts on web form. I am using vb.net as serverside and text/javascript as client side language.How to clear containts all controls in asp.net?
1) Since you want to clear everything on Page PostBack, then you can write a function (subroutine in VB.NET) to clear the controls manually one by one.


ex:


Private Sub Clear()


TextBox1.Text = ';';


DropDownList1.SelectedIndex = -1


.


.


.





End Sub





2) In general there is no special way to do it but If you disable ViewState for the controls one by one, the controls will stop storing their state in ViewState and will clear by themselves. However this might introduce unexpected bugs in the later stages of development.





3) Note: You can add an input of type ';reset'; to clear everything on the client side, however this will clear the results without posting the page back to the server i.e. before you can get to read the entered values by the user


%26lt;input type=';reset'; value=';Clear';%26gt;





4) Another way to clear those on the client is to use Javascript to clear them one by one. However as in 3) the page will not post back to the server





Best Regards

No comments:

Post a Comment