Page.FindControl type casting

Discussion in 'ASP .Net' started by Martin Eyles, Sep 15, 2005.

  1. Martin Eyles

    Martin Eyles Guest

    Hi,

    I am using Page.FindControl in a loop to select some numbered tags

    aTag = Page.FindControl("Tick_" + CStr(aNumber))

    however, when I come to add a style to this

    aTag.Style.Add("visibility", "visible")

    I can't, because aTag is too general a type of object. I need to cast it
    back the the type that it actually is (an HTML control, rather than a plain
    control).

    How would I do this?

    Thanks,
    ME

    --
    Martin Eyles
     
    Martin Eyles, Sep 15, 2005
    #1
    1. Advertising

  2. Cast it:

    Dim MyObject as HTMLControl = Ctype(aType, HTMLControl)
    MyObject.Style.Add("visibility", "visible")


    --
    Gregory A. Beamer
    MVP; MCP: +I, SE, SD, DBA

    ***************************
    Think Outside the Box!
    ***************************


    "Martin Eyles" wrote:

    > Hi,
    >
    > I am using Page.FindControl in a loop to select some numbered tags
    >
    > aTag = Page.FindControl("Tick_" + CStr(aNumber))
    >
    > however, when I come to add a style to this
    >
    > aTag.Style.Add("visibility", "visible")
    >
    > I can't, because aTag is too general a type of object. I need to cast it
    > back the the type that it actually is (an HTML control, rather than a plain
    > control).
    >
    > How would I do this?
    >
    > Thanks,
    > ME
    >
    > --
    > Martin Eyles
    >
    >
    >
    >
     
    =?Utf-8?B?Q293Ym95IChHcmVnb3J5IEEuIEJlYW1lcikgLSBN, Sep 15, 2005
    #2
    1. Advertising

  3. Martin Eyles

    Martin Eyles Guest

    Thanks, :)
    Works a treat!

    --
    Martin Eyles


    "Cowboy (Gregory A. Beamer) - MVP" <> wrote
    in message news:...
    > Cast it:
    >
    > Dim MyObject as HTMLControl = Ctype(aType, HTMLControl)
    > MyObject.Style.Add("visibility", "visible")
    >
    >
    > --
    > Gregory A. Beamer
    > MVP; MCP: +I, SE, SD, DBA
    >
    > ***************************
    > Think Outside the Box!
    > ***************************
    >
    >
    > "Martin Eyles" wrote:
    >
    > > Hi,
    > >
    > > I am using Page.FindControl in a loop to select some numbered tags
    > >
    > > aTag = Page.FindControl("Tick_" + CStr(aNumber))
    > >
    > > however, when I come to add a style to this
    > >
    > > aTag.Style.Add("visibility", "visible")
    > >
    > > I can't, because aTag is too general a type of object. I need to cast it
    > > back the the type that it actually is (an HTML control, rather than a

    plain
    > > control).
    > >
    > > How would I do this?
    > >
    > > Thanks,
    > > ME
    > >
    > > --
    > > Martin Eyles
    > >
    > >
    > >
    > >
     
    Martin Eyles, Sep 15, 2005
    #3
    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. kevin
    Replies:
    11
    Views:
    5,834
    Andrew McDonagh
    Jan 8, 2005
  2. heyo
    Replies:
    3
    Views:
    948
    Dan Pop
    Apr 1, 2004
  3. pete
    Replies:
    4
    Views:
    821
    Dan Pop
    Apr 2, 2004
  4. Wally Barnes
    Replies:
    3
    Views:
    540
    Wally Barnes
    Nov 20, 2008
  5. Samuel Chowdhuri
    Replies:
    1
    Views:
    326
    Alvin Bruney
    Oct 20, 2003
Loading...

Share This Page