WebControls enumeration

Ask a Question related to ASP.NET General, Design and Development.

  1. #1

    Default WebControls enumeration

    Is there enumeration for the WebControls?

    Thanks.


    Vik Guest

  2. Similar Questions and Discussions

    1. HtmlTextWriterStyle enumeration does not contain most of the available CSS properties
      I was using the HtmlTextWriter class, and I noticed that the HtmlTextWriterStyle enumeration contains very few of the available CSS properties. The...
    2. help with UserControl and enumeration in VB.NET
      Hello all, I've got limited experience with VB.NET, so please bear with me... I have a user control that has an Enumeration, "renderMode" which...
    3. Enumeration in Component
      I am using C# in Visual Studio to develop my own component. I inherited from System.ComponentModel.Component. I added a public variable that is a...
    4. Databinding to a collection with a enumeration property
      I have a class that has properties; "value","description" and "type". The first two are string properties, but "type" is a enum type. I create the...
    5. files enumeration
      Hi All, I tried to enumated all files under a specific directory (folder) by first calling MoreFilesX's FSGetDirectoryItems() then I use...
  3. #2

    Default Re: WebControls enumeration

    try something like this

    foreach (Control c in this.Controls)
    {
    if (c.GetType().ToString().Equals("System.Web.UI.WebC ontrols.TextBox")
    {
    // ...do something...
    }
    }



    --
    Regards

    John Timney (Microsoft ASP.NET MVP)
    ----------------------------------------------
    <shameless_author_plug>
    Professional .NET for Java Developers with C#
    ISBN:1-861007-91-4
    Professional Windows Forms
    ISBN: 1861005547
    Professional JSP 2nd Edition
    ISBN: 1861004958
    Professional JSP
    ISBN: 1861003625
    Beginning JSP Web Development
    ISBN: 1861002092
    </shameless_author_plug>
    ----------------------------------------------

    "Vik" <viktorum@==yahoo.com==> wrote in message
    news:OQriV2kRDHA.1720@TK2MSFTNGP10.phx.gbl...
    > Is there enumeration for the WebControls?
    >
    > Thanks.
    >
    >

    John Timney \(Microsoft MVP\) Guest

  4. #3

    Default Re: WebControls enumeration

    If you're using VB try this:

    For Each (Control c in Controls)
    if TypeOf c is System.Web.UI.WebControl Then
    // ...do something...
    Next

    -Mark
    "John Timney (Microsoft MVP)" <xyztimneyj@btinternet.com> wrote in message
    news:OeDr3LlRDHA.1804@TK2MSFTNGP11.phx.gbl...
    > try something like this
    >
    > foreach (Control c in this.Controls)
    > {
    > if (c.GetType().ToString().Equals("System.Web.UI.WebC ontrols.TextBox")
    > {
    > // ...do something...
    > }
    > }
    >
    >
    >
    > --
    > Regards
    >
    > John Timney (Microsoft ASP.NET MVP)
    > ----------------------------------------------
    > <shameless_author_plug>
    > Professional .NET for Java Developers with C#
    > ISBN:1-861007-91-4
    > Professional Windows Forms
    > ISBN: 1861005547
    > Professional JSP 2nd Edition
    > ISBN: 1861004958
    > Professional JSP
    > ISBN: 1861003625
    > Beginning JSP Web Development
    > ISBN: 1861002092
    > </shameless_author_plug>
    > ----------------------------------------------
    >
    > "Vik" <viktorum@==yahoo.com==> wrote in message
    > news:OQriV2kRDHA.1720@TK2MSFTNGP10.phx.gbl...
    > > Is there enumeration for the WebControls?
    > >
    > > Thanks.
    > >
    > >
    >
    >

    Mark Friedman Guest

  5. #4

    Default Re: WebControls enumeration

    actually you need to recurse, or you will miss controls in usercontrols,
    grids, etc.

    walkControls(this.Controls);

    void walkControls (Control c)
    {
    foreach (Control child in this.Controls)
    {
    walkControl(child);

    if
    (child.GetType().ToString().Equals("System.Web.UI. WebControls.TextBox")
    {
    // ...do something...
    }
    }
    }
    }

    "John Timney (Microsoft MVP)" <xyztimneyj@btinternet.com> wrote in message
    news:OeDr3LlRDHA.1804@TK2MSFTNGP11.phx.gbl...
    > try something like this
    >
    > foreach (Control c in this.Controls)
    > {
    > if (c.GetType().ToString().Equals("System.Web.UI.WebC ontrols.TextBox")
    > {
    > // ...do something...
    > }
    > }
    >
    >
    >
    > --
    > Regards
    >
    > John Timney (Microsoft ASP.NET MVP)
    > ----------------------------------------------
    > <shameless_author_plug>
    > Professional .NET for Java Developers with C#
    > ISBN:1-861007-91-4
    > Professional Windows Forms
    > ISBN: 1861005547
    > Professional JSP 2nd Edition
    > ISBN: 1861004958
    > Professional JSP
    > ISBN: 1861003625
    > Beginning JSP Web Development
    > ISBN: 1861002092
    > </shameless_author_plug>
    > ----------------------------------------------
    >
    > "Vik" <viktorum@==yahoo.com==> wrote in message
    > news:OQriV2kRDHA.1720@TK2MSFTNGP10.phx.gbl...
    > > Is there enumeration for the WebControls?
    > >
    > > Thanks.
    > >
    > >
    >
    >

    bruce barker Guest

  6. #5

    Default Re: WebControls enumeration

    Thanks everybody.
    Originally I had code like this which worked fine:

    CtlType = ctl.GetType.Name
    Select Case CtlType
    Case "TextBox"
    ....
    Case "Label"
    ....
    End Select

    I changed it to:
    If TypeOf ctl Is TextBox Then
    ....
    ElseIf TypeOf ctl Is Label Then
    ....
    End If

    This code does not work because TypeOf ctl Is Label = True for example when
    CtlType="CompareValidator".

    Vik

    "Ben" <mustbejoking@120spamsaday.con> wrote in message
    news:uHe%23xAnRDHA.2676@TK2MSFTNGP10.phx.gbl...
    > ToString.Equals() or == is not very type safe, great for displaying to a
    > console or output file but in code you should really use "typeof" and
    "is",
    > after all the code knows these types already and you verify that the code
    is
    > correct at compile time. You need to itterate though the tree of controls
    > too as mentioned.
    >
    > Ben W
    >
    >
    > "John Timney (Microsoft MVP)" <xyztimneyj@btinternet.com> wrote in message
    > news:OeDr3LlRDHA.1804@TK2MSFTNGP11.phx.gbl...
    > > try something like this
    > >
    > > foreach (Control c in this.Controls)
    > > {
    > > if
    (c.GetType().ToString().Equals("System.Web.UI.WebC ontrols.TextBox")
    > > {
    > > // ...do something...
    > > }
    > > }
    > >
    > >
    > >
    > > --
    > > Regards
    > >
    > > John Timney (Microsoft ASP.NET MVP)
    > > ----------------------------------------------
    > > <shameless_author_plug>
    > > Professional .NET for Java Developers with C#
    > > ISBN:1-861007-91-4
    > > Professional Windows Forms
    > > ISBN: 1861005547
    > > Professional JSP 2nd Edition
    > > ISBN: 1861004958
    > > Professional JSP
    > > ISBN: 1861003625
    > > Beginning JSP Web Development
    > > ISBN: 1861002092
    > > </shameless_author_plug>
    > > ----------------------------------------------
    > >
    > > "Vik" <viktorum@==yahoo.com==> wrote in message
    > > news:OQriV2kRDHA.1720@TK2MSFTNGP10.phx.gbl...
    > > > Is there enumeration for the WebControls?
    > > >
    > > > Thanks.
    > > >
    > > >
    > >
    > >
    >
    >

    Vik Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139