473,385 Members | 1,863 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.

Checking if object on page exists

How do you check to see if object exists before accessing it?

For example, I may have an object that I make visible and invisible and I
need to make sure it exists as I am putting this code in a User Control.

UserLoggedOn.visible = true

If this doesn't exists, I get an error.

So how do I test for the object (vb.net and C#) before doing this code?

Thanks,

Tom
Aug 3 '06 #1
7 4264
Try:
if(Page.FindControl("myobjectid")!=null) // It's there
tshad wrote:
How do you check to see if object exists before accessing it?

For example, I may have an object that I make visible and invisible and I
need to make sure it exists as I am putting this code in a User Control.

UserLoggedOn.visible = true

If this doesn't exists, I get an error.

So how do I test for the object (vb.net and C#) before doing this code?

Thanks,

Tom
Aug 3 '06 #2
If(UserLoggedOn != null){
UserLoggedOn.visible = true;
}

"tshad" wrote:
How do you check to see if object exists before accessing it?

For example, I may have an object that I make visible and invisible and I
need to make sure it exists as I am putting this code in a User Control.

UserLoggedOn.visible = true

If this doesn't exists, I get an error.

So how do I test for the object (vb.net and C#) before doing this code?

Thanks,

Tom
Aug 3 '06 #3
<mi*******@hotmail.comwrote in message
news:11**********************@i3g2000cwc.googlegro ups.com...
Try:
if(Page.FindControl("myobjectid")!=null) // It's there
William mentions:

If(UserLoggedOn != null){
UserLoggedOn.visible = true;
}

Which is better or is it 6 of one...?

Thanks,

Tom
>

tshad wrote:
>How do you check to see if object exists before accessing it?

For example, I may have an object that I make visible and invisible and I
need to make sure it exists as I am putting this code in a User Control.

UserLoggedOn.visible = true

If this doesn't exists, I get an error.

So how do I test for the object (vb.net and C#) before doing this code?

Thanks,

Tom

Aug 3 '06 #4
Agreed...

William Sullivan wrote:
If(UserLoggedOn != null){
UserLoggedOn.visible = true;
}

"tshad" wrote:
How do you check to see if object exists before accessing it?

For example, I may have an object that I make visible and invisible and I
need to make sure it exists as I am putting this code in a User Control.

UserLoggedOn.visible = true

If this doesn't exists, I get an error.

So how do I test for the object (vb.net and C#) before doing this code?

Thanks,

Tom

Aug 3 '06 #5
Well, I say that... unless you have a direct reference to the object,
you will need to do the FindControl. If it's directly accessible by
programmatic means, you wouldn't have to.

michae...@hotmail.com wrote:
Agreed...

William Sullivan wrote:
If(UserLoggedOn != null){
UserLoggedOn.visible = true;
}

"tshad" wrote:
How do you check to see if object exists before accessing it?
>
For example, I may have an object that I make visible and invisible and I
need to make sure it exists as I am putting this code in a User Control.
>
UserLoggedOn.visible = true
>
If this doesn't exists, I get an error.
>
So how do I test for the object (vb.net and C#) before doing this code?
>
Thanks,
>
Tom
>
>
>
Aug 3 '06 #6
if (UserLoggedOn != null) UserLoggedOn.visible = true;

-- bruce (sqlwork.com)

"tshad" <ts**********@ftsolutions.comwrote in message
news:u4**************@TK2MSFTNGP06.phx.gbl...
How do you check to see if object exists before accessing it?

For example, I may have an object that I make visible and invisible and I
need to make sure it exists as I am putting this code in a User Control.

UserLoggedOn.visible = true

If this doesn't exists, I get an error.

So how do I test for the object (vb.net and C#) before doing this code?

Thanks,

Tom

Aug 3 '06 #7
Try:
if(Page.FindControl("myobjectid")!=null) // It's there
Not always: if "myobjectid" is a "grandchild" (child of another control
on the page) or deeper, then FindControl will not find it as it
searches only through the direct children.

Hans Kesting
>
tshad wrote:
>How do you check to see if object exists before accessing it?

For example, I may have an object that I make visible and invisible and I
need to make sure it exists as I am putting this code in a User Control.

UserLoggedOn.visible = true

If this doesn't exists, I get an error.

So how do I test for the object (vb.net and C#) before doing this code?

Thanks,

Tom

Aug 4 '06 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: David | last post by:
My email application was working a couple of weeks ago, then all of a sudden I get Error Type: (0x8009000F) Object already exists. I checked the permissions on the machinekeys directory...
1
by: Uttam | last post by:
Hello, How does one suppress the "Object already exists" message when the following statement is executed in ADO? cat.Views.Append "Some_Query", cmd Thanks in advance. Uttam
15
by: Geiregat Jonas | last post by:
is using if(open("file",O_EXCL) != -1){ printf("File does exists")}else{printf("file does not exists"); } a good way of checking if a file exists or not, if not how should I do it ?
1
by: M Keeton | last post by:
I'm building a web site and I need to link to an external page which at any one time may or may not exist (server is not always on). What I need to do is check before redirecting to this page...
0
by: Alun Jones | last post by:
I'm getting the above error in a dialog box from Visual Studio 2005 when trying to sign an assembly using a PFX file, and would like to know how to resolve the problem. Background: The PFX...
2
by: =?Utf-8?B?R2FicmllbCBNw6luZGV6?= | last post by:
Hello everyone. I have a small class that encapsulates some functionallity to work with the RSACryptoServiceProvider. Here is the code of the class i'm using: public class dsRSA { private...
59
oll3i
by: oll3i | last post by:
how to check if an object already exists and return reference to that object
8
by: Alan | last post by:
Hello, I need to write a systemtray program to check every minute if a certain intranet page exists. Would "webBrowser.Navigate" and catching exceptions to it be a good choice in terms of load...
1
by: ThatsIT.net.au | last post by:
I'm getting a 404 error when I shouldn't, the page exists the error is The remote server returned an error: (404) Not Found. the status is 7 witch equates to WebExceptionStatus.ProtocolError ...
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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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.