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

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

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.

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

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

  }
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.