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

Home Posts Topics Members FAQ

Checking Query String

A.M
Hi,

To check if QueryString contains a key I compaire it with null like this
code:

if (Request.QueryS tring["id"]!=null)
{
Label1.Text= Request.QuerySt ring["id"];
}
else
{
Label1.Text= "NoId";
}

Is it the best way to do see if QueryString contains a key or I am missing
some better method in QueryString?

Thanks,
Alan
Nov 18 '05 #1
5 5777
No, that's pretty much it. You can change it to be a shorter using
something like:

Label1.Text = Request.QuerySt ring["id"] == null ? "NoId" :
Requesty.QueryS tring["id"];
"A.M" <no*****@online .nospam> wrote in message
news:%2******** *******@TK2MSFT NGP09.phx.gbl.. .
Hi,

To check if QueryString contains a key I compaire it with null like this
code:

if (Request.QueryS tring["id"]!=null)
{
Label1.Text= Request.QuerySt ring["id"];
}
else
{
Label1.Text= "NoId";
}

Is it the best way to do see if QueryString contains a key or I am missing
some better method in QueryString?

Thanks,
Alan

Nov 18 '05 #2
A.M
Thanks for help

So QueryString doesn't have any method for checking the existance of a key?

Alan
"Marina" <so*****@nospam .com> wrote in message
news:uN******** ******@tk2msftn gp13.phx.gbl...
No, that's pretty much it. You can change it to be a shorter using
something like:

Label1.Text = Request.QuerySt ring["id"] == null ? "NoId" :
Requesty.QueryS tring["id"];
"A.M" <no*****@online .nospam> wrote in message
news:%2******** *******@TK2MSFT NGP09.phx.gbl.. .
Hi,

To check if QueryString contains a key I compaire it with null like this
code:

if (Request.QueryS tring["id"]!=null)
{
Label1.Text= Request.QuerySt ring["id"];
}
else
{
Label1.Text= "NoId";
}

Is it the best way to do see if QueryString contains a key or I am missing some better method in QueryString?

Thanks,
Alan


Nov 18 '05 #3
Have you looked at the .NET documentation? It fully documents all of this -
it is a lot faster to spend 1 minute reading the documentation, then waiting
for hours for someone to respond to your post. You would also probably end
up learning a lot of other useful things.

To answer your question, no there is not a method that will tell if a key
exists. There is a Keys collection - but you would have to loop through it
and check to see if the current key is the same as the one you are looking
for.

This is a lot more work then just checking if the value is null - which by
the way, is just as good a way to test if a key was passed in as anything
else.

"A.M" <no*****@online .nospam> wrote in message
news:uw******** ******@TK2MSFTN GP10.phx.gbl...
Thanks for help

So QueryString doesn't have any method for checking the existance of a key?
Alan
"Marina" <so*****@nospam .com> wrote in message
news:uN******** ******@tk2msftn gp13.phx.gbl...
No, that's pretty much it. You can change it to be a shorter using
something like:

Label1.Text = Request.QuerySt ring["id"] == null ? "NoId" :
Requesty.QueryS tring["id"];
"A.M" <no*****@online .nospam> wrote in message
news:%2******** *******@TK2MSFT NGP09.phx.gbl.. .
Hi,

To check if QueryString contains a key I compaire it with null like this code:

if (Request.QueryS tring["id"]!=null)
{
Label1.Text= Request.QuerySt ring["id"];
}
else
{
Label1.Text= "NoId";
}

Is it the best way to do see if QueryString contains a key or I am missing some better method in QueryString?

Thanks,
Alan



Nov 18 '05 #4
A.M
Thank you for help.

Yes I did have a look at documentation and also searched couple of ASP.NET
portals.
I couldn't find anything.

Sometimes there are techniques that you can not find directly from
documentation. That is when you look for experienced people to ask them.

Alan

"Marina" <so*****@nospam .com> wrote in message
news:uH******** ******@TK2MSFTN GP11.phx.gbl...
Have you looked at the .NET documentation? It fully documents all of this - it is a lot faster to spend 1 minute reading the documentation, then waiting for hours for someone to respond to your post. You would also probably end
up learning a lot of other useful things.

To answer your question, no there is not a method that will tell if a key
exists. There is a Keys collection - but you would have to loop through it
and check to see if the current key is the same as the one you are looking
for.

This is a lot more work then just checking if the value is null - which by
the way, is just as good a way to test if a key was passed in as anything
else.

"A.M" <no*****@online .nospam> wrote in message
news:uw******** ******@TK2MSFTN GP10.phx.gbl...
Thanks for help

So QueryString doesn't have any method for checking the existance of a

key?

Alan
"Marina" <so*****@nospam .com> wrote in message
news:uN******** ******@tk2msftn gp13.phx.gbl...
No, that's pretty much it. You can change it to be a shorter using
something like:

Label1.Text = Request.QuerySt ring["id"] == null ? "NoId" :
Requesty.QueryS tring["id"];
"A.M" <no*****@online .nospam> wrote in message
news:%2******** *******@TK2MSFT NGP09.phx.gbl.. .
> Hi,
>
> To check if QueryString contains a key I compaire it with null like this > code:
>
> if (Request.QueryS tring["id"]!=null)
> {
> Label1.Text= Request.QuerySt ring["id"];
> }
> else
> {
> Label1.Text= "NoId";
> }
>
> Is it the best way to do see if QueryString contains a key or I am

missing
> some better method in QueryString?
>
> Thanks,
> Alan
>
>



Nov 18 '05 #5
Hello!
This is a lot more work then just checking if the value is null - which by
the way, is just as good a way to test if a key was passed in as anything
else.


I agree, but I would have liked to see the .Exists() or .Contains() method
as well.

--
venlig hilsen / with regards
anders borum
--
Nov 18 '05 #6

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

Similar topics

2
1993
by: Andy | last post by:
I haven't done any web work for over a year and for the life of me I cannot remember how to use a query string in a URL. I want the link to be page.aspx?ID=1 then pass 1 into a query like this select * from table where id = "query string value" I know it's simple, I just haven't done it for a long time. Can somebody please help me out? ...
8
8207
by: Phil Powell | last post by:
if (document.location.href.indexOf('?') >= 0) document.location.href = document.location.href.substring(0, document.location.href.indexOf('?')); if (document.location.href.indexOf('#') >= 0) { document.location.href = document.location.href.substring(0, document.location.href.indexOf('#')) + '?' + newUrl; } else { document.location.href =...
1
7125
by: Glenn | last post by:
Searching through google groups, I have not found anyone able to modify the query string of a request. I was hoping to make the query string as short as possible so that a search with many criteria could be bookmarked. I had planned to have the query string be key=value for each criteria But with dropdowns, the default choice is always...
3
7440
by: Dr. Oz | last post by:
Hi, I am trying to read in a query string from one page and build a link to another page based on the query string. Here's the code I am using to read in the query string: <script "text/javascript"> function getQueryVariable(variable) { var query = window.location.search.substring(1);
10
11669
by: Onur Bozkurt | last post by:
I'am sending some data by the querystring. But I don't want it to be seen exactly because of security reasons. Is there a way to encrypt it and later decrypt when reading the querystring...? I would be very happy with some sample code.
4
3097
by: George | last post by:
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
3
7650
by: Jim Lewis | last post by:
I have read several things that state accessing a Web Service through a Query String should work. However, when I try to execute http://localhost/webservice1/service1.asmx/HelloWorld I get the error below. Can I access a Web Service through a Query Sting. I need to send XML to a Flash movie using a Web Service. Thank You, Jim Lewis ...
4
12726
by: Michael Yanowitz | last post by:
Hello: If I have a long string (such as a Python file). I search for a sub-string in that string and find it. Is there a way to determine if that found sub-string is inside single-quotes or double-quotes or not inside any quotes? If so how? Thanks in advance: Michael Yanowitz
24
3072
by: MU | last post by:
Hello I have some code that sets a dropdownlist control with a parameter from the querystring. However, when the querystring is empty, I get an error. Here is my code: Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load If Not Page.IsPostBack Then
0
7612
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8119
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7668
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7964
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
6281
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
5509
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
5218
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...
1
2111
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.