472,096 Members | 1,099 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,096 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 2531
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

25 posts views Thread by Treetop | last post: by
11 posts views Thread by Squid Seven | last post: by
3 posts views Thread by Steve Montague | last post: by
13 posts views Thread by DC Gringo | last post: by
6 posts views Thread by Darren Linsley | last post: by
13 posts views Thread by joenuts | last post: by
6 posts views Thread by Vmusic | last post: by
2 posts views Thread by Netkiller | last post: by
9 posts views Thread by wildernesscat | last post: by

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.