473,396 Members | 1,998 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,396 software developers and data experts.

Test if Object exists

I have an object that may or may not exist on a page. Therefore, I test for
it. But it doesn't seem to work if I do the following:

if not HomeLink is nothing then
HomeLink.NavigateUrl="http://www.staffingworkshop.com/"

I get the error message:
************************************************** ******************
Compilation Error
Description: An error occurred during the compilation of a resource required
to service this request. Please review the following specific error details
and modify your source code appropriately.

Compiler Error Message: BC30451: Name 'HomeLink' is not declared.

Source Error:

Line 40: if not isPostBack then
Line 41: if Session("SiteSourceCompany") is nothing then
Line 42: if not HomeLink is nothing then
HomeLink.NavigateUrl="http://www.stw.com/" <-- error
Line 43: end if
Line 44: Dim OldStart = Session("start") 'Keep this as the clear will
dump it
************************************************** *********************

How do I test to see if an object exists or not?

Thanks,

Tom
Aug 7 '07 #1
2 2625
What you probably want to do is to use FindControl to see if it exists or
not, that will prevent the compile error. In this context 'this' is the
current page.

HyperLink hl = this.FindControl("HomeLink");
if (hl != null) {
hl.NavigateUrl="http://www.staffingworkshop.com/"
}

John
Nice Clean Examples
www.nicecleanexample.com

"tshad" <t@home.comwrote in message
news:er****************@TK2MSFTNGP04.phx.gbl...
>I have an object that may or may not exist on a page. Therefore, I test
for it. But it doesn't seem to work if I do the following:

if not HomeLink is nothing then
HomeLink.NavigateUrl="http://www.staffingworkshop.com/"

I get the error message:
************************************************** ******************
Compilation Error
Description: An error occurred during the compilation of a resource
required to service this request. Please review the following specific
error details and modify your source code appropriately.

Compiler Error Message: BC30451: Name 'HomeLink' is not declared.

Source Error:

Line 40: if not isPostBack then
Line 41: if Session("SiteSourceCompany") is nothing then
Line 42: if not HomeLink is nothing then
HomeLink.NavigateUrl="http://www.stw.com/" <-- error
Line 43: end if
Line 44: Dim OldStart = Session("start") 'Keep this as the clear
will dump it
************************************************** *********************

How do I test to see if an object exists or not?

Thanks,

Tom


Aug 7 '07 #2
On Aug 7, 12:54 pm, "tshad" <t...@home.comwrote:
I have an object that may or may not exist on a page. Therefore, I test for
it. But it doesn't seem to work if I do the following:

if not HomeLink is nothing then
HomeLink.NavigateUrl="http://www.staffingworkshop.com/"

I get the error message:
************************************************** ******************
Compilation Error
Description: An error occurred during the compilation of a resource required
to service this request. Please review the following specific error details
and modify your source code appropriately.

Compiler Error Message: BC30451: Name 'HomeLink' is not declared.

Source Error:

Line 40: if not isPostBack then
Line 41: if Session("SiteSourceCompany") is nothing then
Line 42: if not HomeLink is nothing then
HomeLink.NavigateUrl="http://www.stw.com/" <-- error
Line 43: end if
Line 44: Dim OldStart = Session("start") 'Keep this as the clear will
dump it
************************************************** *********************

How do I test to see if an object exists or not?

Thanks,

Tom
That should work, but you must declare HomeLink, which is why the
compiler is complaining. Once you have it declared in your code, you
can check if it exists or not.
Aug 7 '07 #3

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

Similar topics

25
by: Treetop | last post by:
I have seen some codes that can test for the browser and give values accordingly. I tried to read the FAQ, but was unable to find a simple version of this. What I want is If Netscape-test {...
11
by: Squid Seven | last post by:
I create a pointer to an item: CardSession *cardSession; Then, later, I use new to create an instance of the item and assign it to that pointer: cardSession = new CardSession(); In...
3
by: Steve Montague | last post by:
How does one test to insure a property of an objects exists? The debugger shows the object.property as: "error: 'object.property' does not exist" using: if (object.property != null) results in:...
13
by: DC Gringo | last post by:
How do I test for existence of a file in the file system: If FileExists(myVariable & ".pdf") = True pnlMyPanel.Visible = True End If -- _____ DC G
6
by: Darren Linsley | last post by:
I know this might seem like a dumb question, but how do you test that an object exists. Maybe i should explain a little. I have a variable that points to an object. Now if that oject is...
13
by: joenuts | last post by:
Is it possible for a function to test one of it's passed in variables (reference to object) for validity? I would like the displayString( string &obString) function to verify that obString 1)...
6
by: Vmusic | last post by:
Hi, I am using Javascript to add rows to tables, etc. in a function I am calling. I pass the function the ID of the div, and what I want in the rows, and it will add rows to a table in the div. ...
2
by: Netkiller | last post by:
#!/usr/bin/python # -*- coding: utf-8 -*- """ Project: Network News Transport Protocol Server Program Description: 基于数据库的新闻组,实现BBS前端使用NNTP协议来访问贴子...
9
by: wildernesscat | last post by:
Hello there, I'm looking for a method to test, whether an object has a certain property. Consider the following snippet: class A { var $aaa; } $var = new A; (Assuming that the structure...
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?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development projectplanning, coding, testing,...

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.