Click here to Skip to main content
12,503,189 members (62,942 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as

Stats

6.6K views
4 bookmarked
Posted

Clearing Controls on Submit

, 25 Dec 2014 CPOL
Rate this:
Please Sign up or sign in to vote.
Clearing the controls on Submit

Introduction

When you have a Inventory/Online Adjustment claims website like I do which takes lot of data from users, you would need some function which clears out all the fields at one go.

Background

I am working on a web application which is more similar to make a claim form electronically. Instead of sending adjustment claim forms with lot of paper work, I am designing a web application which gathers all the fields that are necessary to complete a claim form. At one point of time, I was fed up with clearing the controls after user submits the form on website. Then comes the idea which made me dig more into this and finally brought me to write this tip. I have seen people clearing each control by assigning empty string. So I did some research and finally got this working.

//
Public Shared Function FlattenHierachy(ByVal root As Control) As Control()
        Dim list As New List(Of Control)()
        list.Add(root)
        If root.HasControls() Then
            For Each control As Control In root.Controls
                list.AddRange(FlattenHierachy(control))
            Next
        End If
        Return list.ToArray()
    End Function

    Private Sub ClearTextBoxes()
        Dim allControls As Control() = FlattenHierachy(Page)
        For Each control As Control In allControls
            Dim textBox As TextBox = TryCast(control, TextBox)
            If textBox IsNot Nothing Then
                textBox.Text = ""
            End If
        Next
    End Sub

    Protected Sub ClearDropDowns()
        ddlState.SelectedIndex = -1
        ddlADState.SelectedIndex = -1
        ddlDState.SelectedIndex = -1

    End Sub

License

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

Share

About the Author

sudevsu
Software Developer
United States United States
No Biography provided
Group type: Social Group (No members)



You may also be interested in...

Pro
Pro

Comments and Discussions

 
QuestionGeneralized Code Pin
sudevsu31-Dec-14 6:32
groupsudevsu31-Dec-14 6:32 
QuestionCode is generalized Pin
sudevsu30-Dec-14 5:11
groupsudevsu30-Dec-14 5:11 
GeneralMy vote of 4 Pin
Joe Gakenheimer25-Dec-14 5:17
memberJoe Gakenheimer25-Dec-14 5:17 
GeneralRe: My vote of 4 Pin
sudevsu28-Dec-14 11:33
groupsudevsu28-Dec-14 11:33 
Suggestioncode-design-optimization Pin
Mr.PoorEnglish25-Dec-14 3:14
memberMr.PoorEnglish25-Dec-14 3:14 
GeneralRe: code-design-optimization Pin
sudevsu28-Dec-14 11:31
groupsudevsu28-Dec-14 11:31 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.160919.1 | Last Updated 25 Dec 2014
Article Copyright 2014 by sudevsu
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid