Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Query String Problem\VB

Reply
Thread Tools

Query String Problem\VB

 
 
George
Guest
Posts: n/a
 
      02-16-2004
I am trying to check whether a query string is being passed to my .aspx page, like so:

If Not Request.QueryString Is Nothing Then
If CInt(Request.QueryString.GetValues("values")(0)) <> 1 Then
Response.Redirect("../somepage.htm")
End If
Else
Response.Redirect("../somepage.htm")
End If

If there is a query string, everything is fine, but when there isn't one, the app crashes on the
second line :

If CInt(Request.QueryString.GetValues("values")(0)) <> 1 Then

:with this error:

Exception Details: System.NullReferenceException: Object reference not set to an instance of an
object.

What I don't understand, is why is it getting passed this line anyway:

If Not Request.QueryString Is Nothing Then

:when there wasn't even a query string passed? Why didn't it jump down to the Else part, instead?

Thanks,
George


 
Reply With Quote
 
 
 
 
Anatoly
Guest
Posts: n/a
 
      02-16-2004
Check for Request.QueryString.ToString() = string.empty

"George" <------@----.---> wrote in message
news:Sd%Xb.6715$(E-Mail Removed)...
> I am trying to check whether a query string is being passed to my .aspx

page, like so:
>
> If Not Request.QueryString Is Nothing Then
> If CInt(Request.QueryString.GetValues("values")(0)) <> 1 Then
> Response.Redirect("../somepage.htm")
> End If
> Else
> Response.Redirect("../somepage.htm")
> End If
>
> If there is a query string, everything is fine, but when there isn't one,

the app crashes on the
> second line :
>
> If CInt(Request.QueryString.GetValues("values")(0)) <> 1 Then
>
> :with this error:
>
> Exception Details: System.NullReferenceException: Object reference not set

to an instance of an
> object.
>
> What I don't understand, is why is it getting passed this line anyway:
>
> If Not Request.QueryString Is Nothing Then
>
> :when there wasn't even a query string passed? Why didn't it jump down to

the Else part, instead?
>
> Thanks,
> George
>
>



 
Reply With Quote
 
 
 
 
Cezary Nolewajka
Guest
Posts: n/a
 
      02-16-2004
Hi George,

The point is that the QueryString property as such is always set and never
null (nothing). It is an object of NameValueCollection type that can have
zero elements (if query string is empty) but still is instantiated.

So, instead of checking the Request.QueryString existance, you should check
if it has the elemenent (field key) you are looking for:

string[] arString;
arString = Request.QueryString.GetValues("values");

if (arString != null)
{
...
}

Sorry for the c# code, but in nicely transposes to your VB.

--
Cezary Nolewajka
(E-Mail Removed)
remove all "no-sp-am-eh"s to reply


"George" <------@----.---> wrote in message
news:Sd%Xb.6715$(E-Mail Removed)...
> I am trying to check whether a query string is being passed to my .aspx

page, like so:
>
> If Not Request.QueryString Is Nothing Then
> If CInt(Request.QueryString.GetValues("values")(0)) <> 1 Then
> Response.Redirect("../somepage.htm")
> End If
> Else
> Response.Redirect("../somepage.htm")
> End If
>
> If there is a query string, everything is fine, but when there isn't one,

the app crashes on the
> second line :
>
> If CInt(Request.QueryString.GetValues("values")(0)) <> 1 Then
>
> :with this error:
>
> Exception Details: System.NullReferenceException: Object reference not set

to an instance of an
> object.
>
> What I don't understand, is why is it getting passed this line anyway:
>
> If Not Request.QueryString Is Nothing Then
>
> :when there wasn't even a query string passed? Why didn't it jump down to

the Else part, instead?
>
> Thanks,
> George
>
>


 
Reply With Quote
 
George
Guest
Posts: n/a
 
      02-16-2004
Anatoly,

Apparently, ToString is not available in that context. Thanks for the suggestion, though.

George

"Anatoly" <(E-Mail Removed)> wrote in message news:(E-Mail Removed)...
> Check for Request.QueryString.ToString() = string.empty
>
> "George" <------@----.---> wrote in message
> news:Sd%Xb.6715$(E-Mail Removed)...
> > I am trying to check whether a query string is being passed to my .aspx

> page, like so:
> >
> > If Not Request.QueryString Is Nothing Then
> > If CInt(Request.QueryString.GetValues("values")(0)) <> 1 Then
> > Response.Redirect("../somepage.htm")
> > End If
> > Else
> > Response.Redirect("../somepage.htm")
> > End If
> >
> > If there is a query string, everything is fine, but when there isn't one,

> the app crashes on the
> > second line :
> >
> > If CInt(Request.QueryString.GetValues("values")(0)) <> 1 Then
> >
> > :with this error:
> >
> > Exception Details: System.NullReferenceException: Object reference not set

> to an instance of an
> > object.
> >
> > What I don't understand, is why is it getting passed this line anyway:
> >
> > If Not Request.QueryString Is Nothing Then
> >
> > :when there wasn't even a query string passed? Why didn't it jump down to

> the Else part, instead?
> >
> > Thanks,
> > George
> >
> >

>
>



 
Reply With Quote
 
George
Guest
Posts: n/a
 
      02-16-2004
Cezary,

I tried what you suggested and that solved my problem! Learn something new everyday.

Thanks for your help.
George


"Cezary Nolewajka" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
> Hi George,
>
> The point is that the QueryString property as such is always set and never
> null (nothing). It is an object of NameValueCollection type that can have
> zero elements (if query string is empty) but still is instantiated.
>
> So, instead of checking the Request.QueryString existance, you should check
> if it has the elemenent (field key) you are looking for:
>
> string[] arString;
> arString = Request.QueryString.GetValues("values");
>
> if (arString != null)
> {
> ...
> }
>
> Sorry for the c# code, but in nicely transposes to your VB.
>
> --
> Cezary Nolewajka
> (E-Mail Removed)
> remove all "no-sp-am-eh"s to reply
>
>
> "George" <------@----.---> wrote in message
> news:Sd%Xb.6715$(E-Mail Removed)...
> > I am trying to check whether a query string is being passed to my .aspx

> page, like so:
> >
> > If Not Request.QueryString Is Nothing Then
> > If CInt(Request.QueryString.GetValues("values")(0)) <> 1 Then
> > Response.Redirect("../somepage.htm")
> > End If
> > Else
> > Response.Redirect("../somepage.htm")
> > End If
> >
> > If there is a query string, everything is fine, but when there isn't one,

> the app crashes on the
> > second line :
> >
> > If CInt(Request.QueryString.GetValues("values")(0)) <> 1 Then
> >
> > :with this error:
> >
> > Exception Details: System.NullReferenceException: Object reference not set

> to an instance of an
> > object.
> >
> > What I don't understand, is why is it getting passed this line anyway:
> >
> > If Not Request.QueryString Is Nothing Then
> >
> > :when there wasn't even a query string passed? Why didn't it jump down to

> the Else part, instead?
> >
> > Thanks,
> > George
> >
> >

>




 
Reply With Quote
 
Srowe1975 Srowe1975 is offline
Junior Member
Join Date: Oct 2008
Posts: 3
 
      10-15-2008
I am trying response.redirect to do back to the default page. but instead of redirecting to default.aspx it keeps the querystring values in memory and adds them to the new url I am trying to redirect to
any help?

Stephanie
 
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 convert url with query string to url without query string nick Javascript 1 02-13-2011 11:20 PM
Date string problem in query string when posting back =?Utf-8?B?SnVsaWEgQg==?= ASP .Net 5 08-29-2007 02:08 PM
CGI - How to use upload_hook and query the query string ? roadrunner Perl Misc 1 02-08-2006 01:50 AM
Trying to query the Address table data of AdventureWorks database from Query Analyzer - need help! Learner ASP .Net 1 01-30-2006 08:58 PM
Build dynamic sql query for JSTL <sql:query> Anonymous Java 0 10-13-2005 10:01 PM



Advertisments