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

if request.querystring('Id") = ""

On my application, I need to have different action based on the pass in
query string. When the query string is not presented, I try to use

If request.querystring("id") ="" THEN ......

This is what I did in trational asp, however if I did abov in ASP.NET, I
always got an error of "Object reference not set to an instance of an
object. "

How should I solve the problem?

--
Kind regards

Guoqi Zheng
guoqi AT meetholland dot com
Http://www.meetholland.com

Nov 18 '05 #1
4 25322
Hi Guoqi,

You can do two things:

1. Use Request("id") = "".
2. Test for Nothing:
If Not (Request.QueryString("id") Is Nothing) Then ....

Good luck! Ken.

--
Ken Dopierala Jr.
For great ASP.Net web hosting try:
http://www.webhost4life.com/default.asp?refid=Spinlight
If you sign up under me and need help, email me.

"Guoqi Zheng" <no@sorry.nl> wrote in message
news:eR**************@tk2msftngp13.phx.gbl...
On my application, I need to have different action based on the pass in
query string. When the query string is not presented, I try to use

If request.querystring("id") ="" THEN ......

This is what I did in trational asp, however if I did abov in ASP.NET, I
always got an error of "Object reference not set to an instance of an
object. "

How should I solve the problem?

--
Kind regards

Guoqi Zheng
guoqi AT meetholland dot com
Http://www.meetholland.com

Nov 18 '05 #2
In VBScript there is essentially only one datatype, the variant datatype
which changes behavior based upon how it is referenced. That's why a
variable can be used to perform mathematical functions in one case, then
later be treated as a string. In .Net languages there is no variant so
things behave a little different. The Request.Querystring[key] returns an
object. When the key is not found, it returns null instead. An empty string
is not a null value since a null is a very special case all by itself. You
can test to see if the key is null first. You'll have to forgive me, but I
haven't played with VB in a while so I'll show the C# code instead and you
should be able to recognize how to do it in VB.

if(Request.Querystring["id"] == null)

Hope this helps,
Mark Fitzpatrick
Microsoft MVP - FrontPage

"Guoqi Zheng" <no@sorry.nl> wrote in message
news:eR**************@tk2msftngp13.phx.gbl...
On my application, I need to have different action based on the pass in
query string. When the query string is not presented, I try to use

If request.querystring("id") ="" THEN ......

This is what I did in trational asp, however if I did abov in ASP.NET, I
always got an error of "Object reference not set to an instance of an
object. "

How should I solve the problem?

--
Kind regards

Guoqi Zheng
guoqi AT meetholland dot com
Http://www.meetholland.com

Nov 18 '05 #3
Try this syntax:

If IsNothing(Request.Querystring("id")) OrElse Request.Querystring("id")=""
Then...

--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://Steve.Orr.net
"Guoqi Zheng" <no@sorry.nl> wrote in message
news:eR**************@tk2msftngp13.phx.gbl...
On my application, I need to have different action based on the pass in
query string. When the query string is not presented, I try to use

If request.querystring("id") ="" THEN ......

This is what I did in trational asp, however if I did abov in ASP.NET, I
always got an error of "Object reference not set to an instance of an
object. "

How should I solve the problem?

--
Kind regards

Guoqi Zheng
guoqi AT meetholland dot com
Http://www.meetholland.com

Nov 18 '05 #4
To add my $0.02, in .Net a null string evuluates true when compared to an
empty string :
if nothing = "" then
'this will always be true
end if

so checking for both is pointless.

if you simply want to check for not null/nothing:

if NOT Request.QueryString("id") = nothing then
...
end if

if you want to check for not null/nothing as well as not an empty string:

dim id as string = Request.QueryString("id")
IF NOT id IS NOTHING ANDALSO NOT id.length = 0 Then
'id is an actual string
END IF

In VB.Net you absolutely must use AndAlso instead of just And in the above
code, else it'll crash (and you should always be using AndAlso anyways).

checking for a string length = 0 vs comparing to an empty string is a
microsoft recommendation and will show up in FxCop.

Karl
--
MY ASP.Net tutorials
http://www.openmymind.net/
"Steve C. Orr [MVP, MCSD]" <St***@Orr.net> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
Try this syntax:

If IsNothing(Request.Querystring("id")) OrElse Request.Querystring("id")="" Then...

--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://Steve.Orr.net
"Guoqi Zheng" <no@sorry.nl> wrote in message
news:eR**************@tk2msftngp13.phx.gbl...
On my application, I need to have different action based on the pass in
query string. When the query string is not presented, I try to use

If request.querystring("id") ="" THEN ......

This is what I did in trational asp, however if I did abov in ASP.NET, I
always got an error of "Object reference not set to an instance of an
object. "

How should I solve the problem?

--
Kind regards

Guoqi Zheng
guoqi AT meetholland dot com
Http://www.meetholland.com


Nov 18 '05 #5

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

Similar topics

1
by: Pete Mahoney | last post by:
Ok I use a textarea to store data input by the user, and then upon them clicking the submit button I store this data to a database. The problem is once the user inputs too much data (about 3...
1
by: Matt | last post by:
If we use GET protocol, we can use either Request("controlname") or Request.QueryString("controlname") to get the data entered by the user. But if we use POST protocol, we MUST use...
3
by: Buddy Robbins | last post by:
Hey folks, I am re-writing an ASP.Net site for a company. The client wants to be responsible for the static content and navigation of their site, and I'll be responsible for any dynamic content. ...
3
by: Phil Powell | last post by:
'GET THE HTML CONTENT FOR DISPLAY BAND ORIGIN Dim bandOriginDropdown On Error Resume Next set scraper = Server.CreateObject("Microsoft.XMLHTTP") if err then bandOriginDropdown = "" else...
9
by: Peter | last post by:
My problem is the last bit of coding below, the like statement does not work. what I have is a product options field and in it is stored characters i.e. "avcy" etc what the query does is...
3
by: Carpe Diem | last post by:
Hello I have an aspx page that loses Session("user") value after a few minutes even after I set <sessionState mode="InProc" cookieless="false" timeout="300"> in web.config and wrote function...
10
by: thomson | last post by:
Hi, i create a session variable in C# as follows Session , but iam not able to access the variable in VB.net like intmode=Session("var"); Why is that ? Regards
1
by: EoRaptor013 | last post by:
Not sure where to ask this question, but... I'm using a TreeView component to enable browsing file folders in a specific directory (for test purposes /Program Files/). Some users use an ampersand...
5
by: magix8 | last post by:
Hi, I have form GET method, example: index.asp?Type=1&Type=3&Type=4&.... So, I have something like this at the receiver side to retrieve multiple Type value and insert into tables.
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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:
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
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,...

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.