Resetting all form field values in VB.Net using server side approach

Below is a simple approach on how to reset all form field values .I had to use this approach to reset all fields after submit button was clicked .

image

The code above is self explanatory as all its doing is looping through each controls and sub controls within the controls.If the control type matches then it clears the input,selection .

The sample above looks for Textbox,Dropdownlist and Checkbox controls .You can easily expand it to include other controls .

You can call the method from :

i)Page level

ClearInputs(Page.Controls)

ii) Control level

ClearInputs(Me.Controls)

Be careful though while calling the method from Page level as it caused an out of memory exception in my case

For other approaches on resetting from input fields , please refer to ScottGu’s blog post

 

Happy Coding Smile

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s