loop for textboxes
-
Hi I have 20 different textboxes on a page I need to make them all disabled. IS there a way I can do this e.g. in a loop rather then writing out each textbox in the c# code? thanks inadvance! :)
Iterate through the
Page.Controls
collection, check whether the control is a textbox, if yes setEnabled=false
.All C# applications should call Application.Quit(); in the beginning to avoid any .NET problems.- Unclyclopedia How to use google | Ask smart questions
-
Iterate through the
Page.Controls
collection, check whether the control is a textbox, if yes setEnabled=false
.All C# applications should call Application.Quit(); in the beginning to avoid any .NET problems.- Unclyclopedia How to use google | Ask smart questions
thanks for the reply I have this so far for (int x = 0; x < Page.Controls.Count; x++) { if (Page.Controls } How would I check if the control is a button and then set enable to false would it be something like Page.controls.Button.Enabled = false? thanks!!
-
thanks for the reply I have this so far for (int x = 0; x < Page.Controls.Count; x++) { if (Page.Controls } How would I check if the control is a button and then set enable to false would it be something like Page.controls.Button.Enabled = false? thanks!!
foreach (Control c in Page.Controls)
{
if(c is TextBox)
c.Enabled = false;
}All C# applications should call Application.Quit(); in the beginning to avoid any .NET problems.- Unclyclopedia How to use google | Ask smart questions
-
foreach (Control c in Page.Controls)
{
if(c is TextBox)
c.Enabled = false;
}All C# applications should call Application.Quit(); in the beginning to avoid any .NET problems.- Unclyclopedia How to use google | Ask smart questions
-
Hi it says attrivute enabled is not recognised, I can make it invisible but not disabled what would be the reason for this? thanks so far! :)
Try this
foreach (Control c in form1.Controls)
{
if (c is TextBox)
(c as TextBox).Enabled = false;
}where
form1
is your form name.All C# applications should call Application.Quit(); in the beginning to avoid any .NET problems.- Unclyclopedia How to use google | Ask smart questions
-
Try this
foreach (Control c in form1.Controls)
{
if (c is TextBox)
(c as TextBox).Enabled = false;
}where
form1
is your form name.All C# applications should call Application.Quit(); in the beginning to avoid any .NET problems.- Unclyclopedia How to use google | Ask smart questions
-
Hi The syntax built this time but none of the textboxes are disabled. Am I missing something? thanks
It's working here. Put break point and check it is executing.
All C# applications should call Application.Quit(); in the beginning to avoid any .NET problems.- Unclyclopedia How to use google | Ask smart questions
-
It's working here. Put break point and check it is executing.
All C# applications should call Application.Quit(); in the beginning to avoid any .NET problems.- Unclyclopedia How to use google | Ask smart questions
-
Hi I have 20 different textboxes on a page I need to make them all disabled. IS there a way I can do this e.g. in a loop rather then writing out each textbox in the c# code? thanks inadvance! :)
I think you are doing little bit mistake in foreach line. Please try below code foreach (Control c in this.Page.Form.Controls ) { if (c is TextBox) ((WebControl)c).Enabled = false; }
Parwej Ahamad g.parwez@gmail.com
-
I think you are doing little bit mistake in foreach line. Please try below code foreach (Control c in this.Page.Form.Controls ) { if (c is TextBox) ((WebControl)c).Enabled = false; }
Parwej Ahamad g.parwez@gmail.com
-
I think you are doing little bit mistake in foreach line. Please try below code foreach (Control c in this.Page.Form.Controls ) { if (c is TextBox) ((WebControl)c).Enabled = false; }
Parwej Ahamad g.parwez@gmail.com
This code is working ;)