0

I have totally Eight textboxes in my aspx page. When the page loads, disable any four textboxes randomly. Is there any option for doing this simply, If there means, pls let me know.

Thanks In Advance

4
Contributors
3
Replies
10
Views
3 Years
Discussion Span
Last Post by elsunhoty
0

try to do something like this

'assume we have 8 textboxes with following name txt1,txt2,txt3,txt4,txt5,txt6,txt7,txt8
'now use this code

Random random = new Random();

for(int i = 0;i<=3;i++)
{
    int randomNumber = random.Next(1, 8);
    if(randomNumber == 1)
        txt1.Enable= false;

    if(randomNumber == 1)
        txt1.Enable= false;

    if(randomNumber == 1)
        txt1.Enable= false;
        .
        .
        .
        'you can also use switch statement for this.
}

This is not the ideal solution. If you find any shortest way please do share here.

regards

0

hmm.. the same random number can be selected more than once during the loop. To ensure that you actually have 4 random numbers at the end of hte process, you'd have to store the random number during each cycle and make sure that the next random number wasnt already chosen.

0
  int randomNumber = random.Next(0, 1);

  if (randomNumber ==1)
  {
  textbox.enable=false;
  }
  else
  {
    textbox.enable=true;

  }
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.