473,385 Members | 2,210 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Finding Controls in a Page

I am trying to go through all controls in a page and if its a text box then making it non editable.... how do i go about it...
May 21 '07 #1
10 2064
Plater
7,872 Expert 4TB
There is like a Page.Controls or Page.Components or something.
loop through them checking to see if they are of type textbox.
If they are, mark them as readonly.
May 21 '07 #2
I am trying to do something like this... but their is no option as where to match the control if its a text box....??

foreach (Controls control in Page.Controls)
{
if control.?? = textbox
{
}

}
May 21 '07 #3
Plater
7,872 Expert 4TB
should be something like
Expand|Select|Wrap|Line Numbers
  1. foreach (Control c in Page.Controls)
  2. {
  3.    if (c.GetType()==typeof(TextBox)
  4.    {
  5.       ((TextBox)c).ReadOnly=true;
  6.    }
  7. }
  8.  
May 21 '07 #4
The system is not giving my any option when I put a . after c.....

when i try this

if(c.??? I get nothing.... have you tried this on your system???
May 21 '07 #5
Plater
7,872 Expert 4TB
The system is not giving my any option when I put a . after c.....

when i try this

if(c.??? I get nothing.... have you tried this on your system???
Did you note this line change?
Expand|Select|Wrap|Line Numbers
  1. foreach (Controls c in Page.Controls)
  2.  
May 21 '07 #6
When I type in your code

foreach (Controls c in Page.Controls)
{
if (c.GetType() == typeof(TextBox))
{
// No Statements here till now
}
}

It gives me followiing error.....

........Controls' is a 'namespace' but is used like a 'type'

The type or namespace name 'TextBox' could not be found (are you missing a using directive or an assembly reference?)
May 21 '07 #7
Plater
7,872 Expert 4TB
When I type in your code

foreach (Controls c in Page.Controls)
{
if (c.GetType() == typeof(TextBox))
{
// No Statements here till now
}
}

It gives me followiing error.....

........Controls' is a 'namespace' but is used like a 'type'

The type or namespace name 'TextBox' could not be found (are you missing a using directive or an assembly reference?)
OOPS! That is my fault!
Expand|Select|Wrap|Line Numbers
  1. foreach (Control c in Page.Controls)
  2.  
May 21 '07 #8
The type or namespace name 'Control' could not be found (are you missing a using directive or an assembly reference?)

The type or namespace name 'TextBox' could not be found (are you missing a using directive or an assembly reference?)

Maybe it will work... I guess...:)

where do I include textbox and contol???

I have included
using system.text.
using system.collections
using system
May 21 '07 #9
Plater
7,872 Expert 4TB
Well if you have Page.Controls and don't have Control, you're in bigger trouble then not matching a textbox type.
But yeah, go to the aspx code page and look for the include/using statements up top and add them to the file were you are.
May 21 '07 #10
hey...thanx ma.... spelling mstake he he... worst thing to do.....

got it now... thanx a lot....
May 21 '07 #11

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Rob | last post by:
You can find datagrid in page by refering the form. Gatagrid is a child control of Form. Here is the code ----------------- Dim ctl As New Control For Each ctl In...
1
by: Elizabeth Harmon | last post by:
Hi All I am new to .Net and cant seem to fingure something out. I Dynamically create a table based on data pulled from my SQL DB. As the Information and table are shaped, i insert List Boxes...
3
by: Simon Harvey | last post by:
Hi All. In one of my user controls I add a textbox to a placeholder sitting on the user control. txtUsername = new TextBox(); txtUsername.ID = "txtUsername";...
2
by: accyboy1981 | last post by:
Hi, I'm creating an asp text box dynamically within an asp table. I know the id as this is not dynamic (txBxPass). I need to get the text of this text box when an asp button is pressed. I know...
1
by: gnana | last post by:
Hi, I want to find controls in a ASP.NET page using System.Reflection.Assembly. I have to create an Application to set the Permission(visible/editable) for each control on the page, for this i...
2
by: MLH | last post by:
I can't seem to find an A97 HELP blurb telling me how to make a specific Tab Page active from within VBA. I have a form with 3 tabs. They work great. I want to optionally make the first, second or...
2
by: Alex Maghen | last post by:
I want to create a utility function that will seach the current page for one of my UserControls by it's type. So, let's say that I have a UserControl whose class I defined as follows: namespace...
4
by: jrett | last post by:
I'm new to ASP.NET and fairly inexperienced with web development in general, but I've been a professional software dev for over 10 years, C++, Unix and windows, C# the past 4 years. I've been...
1
by: Mufasa | last post by:
I have a page that has a master page. I'm writing generic code to find multiple controls on the page (I have a number of controls called tbName1, tbName2, tbName3, ..., tbName20) and rather than...
4
by: karthik25 | last post by:
Hi All, I have a problem in finding control in a dynamically created updated panel. I have given the code below. Following is just a starting effort in a completely dynamic user control. I am...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.