How to disable a Control dynamically

  • Thread starter Thread starter Ahmed Jewahar
  • Start date Start date
A

Ahmed Jewahar

Dear All,

I have about 31 ASP.TextBox controls on my WebForm. The name pattern of
the TextBox are as follows:
"TextBox1", "TextBox2"...."TexBox31".

I want to disable some of them dynamically. I have done the same in ASP.
But, i don't know how to in ASP.NET. Following are my code which done
in ASP:

For i = 1 to 31
mTextBox = "TextBox" & ltrim(str(i))
mTextBox.enabled = false
Next i

above is just like to show u an example. How can I implement the above
in ASP.NET.

Appreciate your help..

Rgds-
 
You can use the FindControl method on the Page to find the control with the
given name. You could then set the Enabled property to false.

Dim tb As TextBox
For i = 1 To 31
tb = DirectCast( FindControl( "TextBox" & I ), TextBox )
tb.Enabled = false
Next

- Paul Alexander
 
Paul,

Thank you very much for your help.. I will btr tryin your code today.

I have one more question and hope that you can solve this as well.

In the Webform I have One Server Control (Image). This control has been
hided on PageLoad event. "Image1.Visibile = False"

Also I have one command button on the same WebForm. Onclick event of
this command button, at the first line of the Sub I put the following to
make "Image1" visibile to user: "Image1.Visible = True". After this line
I have set of process that will take about 2 min. to complete.

The problem is that "Image1" is not visible to user until system
complete the whole process which is written in "Onclick" event of the
command button. Any idea on as how to resolve this.

Apprecite your help..

Regards,

Ahmed
 
Back
Top