Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Test if Object exists

Reply
Thread Tools

Test if Object exists

 
 
tshad
Guest
Posts: n/a
 
      08-07-2007
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


 
Reply With Quote
 
 
 
 
John Mott
Guest
Posts: n/a
 
      08-07-2007
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" <(E-Mail Removed)> wrote in message
news:erWS%(E-Mail Removed)...

>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
>
>



 
Reply With Quote
 
 
 
 
lee whitbeck
Guest
Posts: n/a
 
      08-07-2007
On Aug 7, 12:54 pm, "tshad" <(E-Mail Removed)> wrote:
> 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.


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to determine if an object exists in the CALL object George Javascript 7 10-03-2009 04:02 PM
How to check if a directory exists? folder.exists() does not work! Ulf Meinhardt Java 8 08-28-2009 12:26 PM
finding if file exists or not in apache webdav server and if exists what is the mime type of it.... Totan Java 0 04-17-2006 05:13 AM
test to see if object exists with new/delete usage Squid Seven C++ 11 07-11-2005 12:41 PM
test test test test test test test Computer Support 2 07-02-2003 06:02 PM



Advertisments