Variable Name Modifier - Is it Possible ?

Discussion in 'ASP .Net' started by mosscliffe, May 4, 2006.

  1. mosscliffe

    mosscliffe Guest

    I have several buttons on a page btn1, btn2, btn3, btn4 ... btnn

    I wish to control their visibilty

    for x = 1 to btnCount
    btn[var x value].visible = false
    next x

    where the x is used to convert to a number making the variable name
    btn1, btn2 etc

    I used to be able to do this in shell scripting, but I can not find how
    to do it in VB2005.

    Any help, especially an example much appreciated
    mosscliffe, May 4, 2006
    #1
    1. Advertising

  2. see

    Page.FindControl(name)

    -- bruce (sqlwork.com)

    "mosscliffe" <> wrote in message
    news:...
    >I have several buttons on a page btn1, btn2, btn3, btn4 ... btnn
    >
    > I wish to control their visibilty
    >
    > for x = 1 to btnCount
    > btn[var x value].visible = false
    > next x
    >
    > where the x is used to convert to a number making the variable name
    > btn1, btn2 etc
    >
    > I used to be able to do this in shell scripting, but I can not find how
    > to do it in VB2005.
    >
    > Any help, especially an example much appreciated
    >
    bruce barker \(sqlwork.com\), May 4, 2006
    #2
    1. Advertising

  3. mosscliffe

    mosscliffe Guest

    Bruce

    page.findcontrol("btn" & x.tostring).visible = false

    or

    page.findcontrol("btn" & x.tostring).visible = true


    Brilliant many thanks

    Richard
    mosscliffe, May 4, 2006
    #3
  4. As an alternative, you could make an array that contains references to
    the buttons. In C#:

    Button[] btn = new Button[] { btn1, btn2, bnt3, btn4 ... btnn };

    btn[x].visible = false;

    Not as flexible as FindControl, but more efficient.

    mosscliffe wrote:
    > Bruce
    >
    > page.findcontrol("btn" & x.tostring).visible = false
    >
    > or
    >
    > page.findcontrol("btn" & x.tostring).visible = true
    >
    >
    > Brilliant many thanks
    >
    > Richard
    >
    =?ISO-8859-1?Q?G=F6ran_Andersson?=, May 4, 2006
    #4
    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. Robert Elliot

    Subclass only modifier possible?

    Robert Elliot, Jun 7, 2004, in forum: Java
    Replies:
    5
    Views:
    910
    Dale King
    Apr 15, 2006
  2. Replies:
    3
    Views:
    709
  3. Bobby Chamness
    Replies:
    2
    Views:
    2,390
    Joe Smith
    Apr 22, 2007
  4. mfglinux
    Replies:
    11
    Views:
    697
    Roberto Bonvallet
    Sep 12, 2007
  5. David Filmer
    Replies:
    19
    Views:
    240
    Kevin Collins
    May 21, 2004
Loading...

Share This Page