.NETGURU
Get object by Id
Messages   Related Types
This message was discovered on ASPFriends.com 'aspngcs' list.


Eugene Valencia Jr.
I have the Id of an object(a DropDownList web control) as a string of
course and I want to get the object based on this Id. Is there a way to
do this in C#?

Reply to this message...
 
    
Ollie Cornes

Hi Eugene,

Have a look at the FindControl() method. It's a member of the Control class,
so it exists on the Page object and all the controls in the page. You'll
probably just want to do FindControl(controlName) from your code behind.

Ollie
--
http://www.richtextbox.com/
The no. 1 content editor for ASP.NET

----- Original Message -----
From: "Eugene Valencia Jr." <Click here to reveal e-mail address>
To: "aspngcs" <Click here to reveal e-mail address>
Sent: Tuesday, July 30, 2002 11:58 AM
Subject: [aspngcs] Get object by Id

I have the Id of an object(a DropDownList web control) as a string of
course and I want to get the object based on this Id. Is there a way to
do this in C#?

| [aspngcs] member Click here to reveal e-mail address = YOUR ID
| http://www.asplists.com/asplists/aspngcs.asp = JOIN/QUIT

Reply to this message...
 
    
Calhoun, Dot Net Guruhew
WW91IHdvdWxkIGRvIHNvbWV0aGluZyBsaWtlLi4uDQogDQpTeXN0ZW0uV2ViLlVJLldlYkNvbnRy
b2xzLkRyb3BEb3duTGlzdCBkZGwgPSBQYWdlLkZpbmRDb250cm9sKCJDb250cm9sTmFtZSIpOw0K
IA0KDQoJLS0tLS1PcmlnaW5hbCBNZXNzYWdlLS0tLS0gDQoJRnJvbTogRXVnZW5lIFZhbGVuY2lh
IEpyLiBbbWFpbHRvOmV1Z2VuZXZhbEB0ZWFteWVoZXkuY29tXSANCglTZW50OiBUdWUgNy8zMC8y
MDAyIDY6NTggQU0gDQoJVG86IGFzcG5nY3MgDQoJQ2M6IA0KCVN1YmplY3Q6IFthc3BuZ2NzXSBH
ZXQgb2JqZWN0IGJ5IElkDQoJDQoJDQoNCglJIGhhdmUgdGhlIElkIG9mIGFuIG9iamVjdChhIERy
b3BEb3duTGlzdCB3ZWIgY29udHJvbCkgYXMgYSBzdHJpbmcgb2YNCgljb3Vyc2UgYW5kIEkgd2Fu
dCB0byBnZXQgdGhlIG9iamVjdCBiYXNlZCBvbiB0aGlzIElkLiAgSXMgdGhlcmUgYSB3YXkgdG8N
CglkbyB0aGlzIGluIEMjPw0KCQ0KCXwgW2FzcG5nY3NdIG1lbWJlciBtY2FsaG91bkBkaWdpdGFs
ZGVtZWFub3IuY29tID0gWU9VUiBJRA0KCXwgaHR0cDovL3d3dy5hc3BsaXN0cy5jb20vYXNwbGlz
dHMvYXNwbmdjcy5hc3AgPSBKT0lOL1FVSVQNCgkNCg0K
Reply to this message...
 
    
Andy Smith
note that FindControl isn't as cool as it used to be, in that it doesn't =
search beyond the current INamingContainer. So Page.FindControl will =
only look at Page-level controls, and nothing inside a UserControl or =
DataGrid or any other INamingContainer.

__
Andy Smith
Keyboard Jockey #3a7-2.78.1

[Original message clipped]

Reply to this message...
 
    
chris
This is true, but since these controls do implement INamingContainer
themselves, you could say
Page.FindControl(controlOnPage).FindControl(controlYouWant);

-Chris Frazier
.NET Solution Developer
Velocity Databank, Inc.
www.velocitydatabank.com

-----Original Message-----
From: Andy Smith [mailto:Click here to reveal e-mail address]
Sent: Tuesday, July 30, 2002 10:30 AM
To: aspngcs
Subject: [aspngcs] Re: Get object by Id

note that FindControl isn't as cool as it used to be, in that it doesn't
search beyond the current INamingContainer. So Page.FindControl will only
look at Page-level controls, and nothing inside a UserControl or DataGrid or
any other INamingContainer.

__
Andy Smith
Keyboard Jockey #3a7-2.78.1

[Original message clipped]

| [aspngcs] member Click here to reveal e-mail address = YOUR ID
| http://www.asplists.com/asplists/aspngcs.asp = JOIN/QUIT

Reply to this message...
 
 
System.Web.UI.INamingContainer
System.Web.UI.Page
System.Web.UI.UserControl
System.Web.UI.WebControls.DataGrid
System.Web.UI.WebControls.DropDownList
System.Windows.Forms.DataGrid
System.Windows.Forms.UserControl




ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
Ad


Need Dot Net Interview Questions?
Ask ExamGuru, Inc. for advice and help on Passing .Net Interviews
.Net Projects
Best-of-breed application framework for .NET projects, developed by ExamGuru, Inc. and ExamGuru IT
Free .net Help
Commission ExamGuru, Inc. and his team for your next bespoke software project
FogBUGZ
The only bug tracking system carefully crafted with one goal in mind: helping teams create great software.
Awesome Tools
If you don't know about these, you're missing out... IT Certification Questions
IT Interview Questions
Free Oracle 10g Training
MCSE Boortcamp
Cisco Study Guides
Cheap Study Guides
Exact Questions
Dot Net Interview Questions
Oracle OCP
Cheap Travel
Designer Perfumes - Wholesale Prices
Free Programming Tutorials
 
ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
 Copyright © ExamGuru, Inc. 2001-2006
Contact Us - Terms of Use - Privacy Policy - www.dot-net-guru.com - www.examguru.net - www.oraclesource.net - www.itinterviews.net - www.examguru.net/ITCertification