473,569 Members | 2,704 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Request.Queryst ring

Hi All,

This problem is really annoying me, as I am sure there is
a simple solution to it.

If I try to read a querystring value in the Page_Load
event and that querystring does not exist I get the error:

Object reference not set to an instance of an object

How do I check if the querystring is there before I try
to use it in my code?

Thanks,
Steve
Nov 18 '05 #1
4 1611
Indexing into the querystring object doesn't fail. It is something you are
doing with the result of that, that is failing, such as calling Substring,
or using it elsewhere.

"Steve" <ms**@zuna.co.u k> wrote in message
news:02******** *************** *****@phx.gbl.. .
Hi All,

This problem is really annoying me, as I am sure there is
a simple solution to it.

If I try to read a querystring value in the Page_Load
event and that querystring does not exist I get the error:

Object reference not set to an instance of an object

How do I check if the querystring is there before I try
to use it in my code?

Thanks,
Steve

Nov 18 '05 #2
Before accessing your querystring value use

Request.Params. Get["<Your Parameter>"] != null

to check if those exists.
Thanks,
-Shan

-----Original Message-----
Hi All,

This problem is really annoying me, as I am sure there is
a simple solution to it.

If I try to read a querystring value in the Page_Load
event and that querystring does not exist I get the error:

Object reference not set to an instance of an object

How do I check if the querystring is there before I try
to use it in my code?

Thanks,
Steve
.

Nov 18 '05 #3

I get the error when I try to do this:

Dim sID As String
sID = Request.QuerySt ring("id")
If sID.Length > 0 Then
--- my code ---
Should I be doing it another way?

Steve

-----Original Message-----
Indexing into the querystring object doesn't fail. It is something you aredoing with the result of that, that is failing, such as calling Substring,or using it elsewhere.

"Steve" <ms**@zuna.co.u k> wrote in message
news:02******* *************** ******@phx.gbl. ..
Hi All,

This problem is really annoying me, as I am sure there is a simple solution to it.

If I try to read a querystring value in the Page_Load
event and that querystring does not exist I get the error:
Object reference not set to an instance of an object

How do I check if the querystring is there before I try
to use it in my code?

Thanks,
Steve

.

Nov 18 '05 #4
Well, there you go. You are trying to access the Length property of a
string variable that is set to Nothing. So the QueryString is working just
fine - it does not cause problems, it returns Nothing if 'id' isn't there..
You need to check if sID is nothing or not, before you try to do anything
with it:

If Not IsNothing(sID) Then
....
"Steve" <an*******@disc ussions.microso ft.com> wrote in message
news:0b******** *************** *****@phx.gbl.. .

I get the error when I try to do this:

Dim sID As String
sID = Request.QuerySt ring("id")
If sID.Length > 0 Then
--- my code ---
Should I be doing it another way?

Steve

-----Original Message-----
Indexing into the querystring object doesn't fail. It

is something you are
doing with the result of that, that is failing, such as

calling Substring,
or using it elsewhere.

"Steve" <ms**@zuna.co.u k> wrote in message
news:02******* *************** ******@phx.gbl. ..
Hi All,

This problem is really annoying me, as I am sure there is a simple solution to it.

If I try to read a querystring value in the Page_Load
event and that querystring does not exist I get the error:
Object reference not set to an instance of an object

How do I check if the querystring is there before I try
to use it in my code?

Thanks,
Steve

.

Nov 18 '05 #5

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

Similar topics

5
2558
by: momo | last post by:
Hello Newsgroup, I want to pass a Request.Form variable to an ASP form, through the url for example lets say i have a form with a textfiled called "txtName" if i click the submit button for example the asp page reads the content of this txtName as Request.Form("txtName") I want to achieve that the asp form is accessed through a URL...
4
2727
by: Max | last post by:
Hello. This is the first time I've posted to a newsgroup, and I do this because I'm in desperate need of help. I'm working a user management system, and when I activate a user that has registered to my system, the current admin user logged in gets logged out. I can't seem to work out how - I can't even trace back where some of the variables...
5
2394
by: Ivan | last post by:
hi, I saw some program using "request("fieldname") " instead of "request.QueryString" to get the value from URL, what's the different ?? thanks
0
3084
by: Anders Borum | last post by:
Hello! I would like to request a new method on the XsltArgumentList class, allowing developers to check the presense of a key/value pair. If you try to add a key/value pair that has already been defined in the list, an exception is thrown. Rather than using the "GetParam" method, it would be usefull to have a method called ".Exists"...
1
1870
by: FD | last post by:
For performance reason, the follwoing code (C#) to capture all the Request collection contexts is NOT recommended: string ID = Request.QueryString; But how to Capture the individual Request properties needed in the application? Thanks, FD
4
13199
by: Steve | last post by:
Hi- I'd like to set values in the QueryString if I detect that a user submits a bad value, say... ?id=333 where there is no id '333', I would like to set it to '0' for example. I tried to use Request.QueryString.Set("id", "0"); it says it is Read Only. How can this be done? Why is there a Set() method if you can't use it?
2
1835
by: mahsa | last post by:
Hi have have some link like thi http://x.com/Shoppingcart.aspx?pn=ps50210&qty_ps50210=1&pn=excel&qty_excel=1&pn=l4504000&qty_l4504000=1&sku=PS50210&cat=laminate&action=updat now I want to request the dat I use this code in as <%For Each strPartNo In Request.QueryString("pn" lngQty = Request.QueryString("qty_" & strPartNo strPartNo =...
4
25347
by: Guoqi Zheng | last post by:
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. " ...
6
3790
by: Ammar | last post by:
Dear All, I'm facing a small problem. I have a portal web site, that contains articles, for each article, the end user can send a comment about the article. The problem is: I the comment length is more that 1249 bytes, then the progress bar of the browser will move too slow and then displaying that the page not found!!!! If the message is...
7
9650
by: =?Utf-8?B?QVRT?= | last post by:
HOWTO Make CStr for JavaScript on ASP w/ Request.Form and QueryString In ASP, Request.Form and Request.QueryString return objects that do not support "toString", or any JavaScript string operation on parameters not passed. Example: Make a TST.asp and post to it as TST.asp?STATE=TEST <%@ Language=JavaScript %> <%
0
7698
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7970
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6284
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 project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5513
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5219
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3653
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3640
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1213
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
937
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.