Clear all controls on a web page

Discussion in 'ASP .Net' started by Guest, Aug 6, 2008.

  1. Guest

    Guest Guest

    I'm trying to clear all the textboxes on a webpage, this is the code I use
    in an application, but a control doesn't have a text member in a
    webform????? I get an error on the "ctl.text" saying there is no text
    member. How would I clear all textboxes in a web form.

    Private Sub ClearTextboxes

    Dim ctl as Control

    For each ctl in me.controls

    if typeof ctl is textbox

    ctl.text = string.empty


    End If

    Next
     
    Guest, Aug 6, 2008
    #1
    1. Advertising

  2. Guest

    Teemu Keiski Guest

    Hi,

    here is an example how to loop through controls on the Page:
    http://www.aspnet101.com/aspnet101/tips.aspx?id=97

    If you want to access Text property, you need to have typed reference (cast
    it to TextBox set the value to the property).

    --
    Teemu Keiski
    AspInsider, ASP.NET MVP
    http://blogs.aspadvice.com/joteke
    http://teemukeiski.net

    <tester> wrote in message news:...
    > I'm trying to clear all the textboxes on a webpage, this is the code I use
    > in an application, but a control doesn't have a text member in a
    > webform????? I get an error on the "ctl.text" saying there is no text
    > member. How would I clear all textboxes in a web form.
    >
    > Private Sub ClearTextboxes
    >
    > Dim ctl as Control
    >
    > For each ctl in me.controls
    >
    > if typeof ctl is textbox
    >
    > ctl.text = string.empty
    >
    >
    > End If
    >
    > Next
    >
    >
    >
    >
    >
    >
     
    Teemu Keiski, Aug 6, 2008
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ricardo Corsi P. Cesar

    How can i do to clear all the textbox using controls?

    Ricardo Corsi P. Cesar, Nov 21, 2003, in forum: ASP .Net
    Replies:
    3
    Views:
    526
    Kiran Kumar
    Nov 21, 2003
  2. bienwell
    Replies:
    0
    Views:
    3,406
    bienwell
    Nov 17, 2005
  3. Duk Lee
    Replies:
    2
    Views:
    746
    Alexey Smirnov
    Jul 23, 2007
  4. David

    Response.Clear() doesn't clear

    David, Jan 31, 2008, in forum: ASP .Net
    Replies:
    2
    Views:
    1,047
    Mark Fitzpatrick
    Jan 31, 2008
  5. InvalidLastName

    Unrecognized element 'add' after <clear></clear>

    InvalidLastName, Feb 26, 2007, in forum: ASP .Net Web Services
    Replies:
    3
    Views:
    980
    Steven Cheng[MSFT]
    Mar 6, 2007
Loading...

Share This Page