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

how to validate QueryString?

I have an ID which I pass from the QueryString["id"]. The id is integer only
and I want before performing any action to validate if the Id is valid
integet.

Jul 23 '07 #1
4 1992
On Jul 23, 1:33 pm, "Jassim Rahma" <jra...@hotmail.comwrote:
I have an ID which I pass from the QueryString["id"]. The id is integer only
and I want before performing any action to validate if the Id is valid
integet.
for example

int id;
try {
id = Request.QueryString["id"];
} catch {
return; // id is wrong
}

Jul 23 '07 #2
int id = 0;
if (int.TryParse(QueryString["id"], out id))
{
// id is ok
}
else
{
// it isn't
}

"Jassim Rahma" <jr****@hotmail.comwrote in message
news:F8**********************************@microsof t.com...
>I have an ID which I pass from the QueryString["id"]. The id is integer
only
and I want before performing any action to validate if the Id is valid
integet.


Jul 23 '07 #3
Alexey,

You should do some research on using Try/Catch to take care of programming
logic. Doing so should be avoided at all cost. Using Try/Catch is very
inneficient and can make applications perform very slowy.

Aidy's example utilizing TryParse is an incredibly more efficient way to
handle this.

Regards,

--
S. Justin Gengo, MCP
justin@aboutfortunate[-NoSpam-].com

Free code library at:
www.aboutfortunate.com


"Alexey Smirnov" <al************@gmail.comwrote in message
news:11**********************@n2g2000hse.googlegro ups.com...
On Jul 23, 1:33 pm, "Jassim Rahma" <jra...@hotmail.comwrote:
>I have an ID which I pass from the QueryString["id"]. The id is integer
only
and I want before performing any action to validate if the Id is valid
integet.

for example

int id;
try {
id = Request.QueryString["id"];
} catch {
return; // id is wrong
}
Jul 23 '07 #4
S. Justin Gengo wrote:
Alexey,

You should do some research on using Try/Catch to take care of
programming logic. Doing so should be avoided at all cost. Using
Try/Catch is very inneficient and can make applications perform very slowy.

Aidy's example utilizing TryParse is an incredibly more efficient way to
handle this.
In this case either way is valid. A non-integer value might very well be
considered to be an exceptional situation. In that case performance is
not an issue. It's true that exceptions should not be used in normal
program flow, but if the validation fails, the normal program flow is
out of the picture anyway.

-

The catch, however, should _not_ catch any exception, it should catch
only FormatException and OverflowException. Don't catch exceptions that
you don't know how to handle.

Also the code handling the exception should _not_ simply do a return, it
should actually handle the situation.

--
Göran Andersson
_____
http://www.guffa.com
Jul 23 '07 #5

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

Similar topics

3
by: Arpan | last post by:
A link has the following URL: <a href="Page1.asp?cname=<%= Request.QueryString("cname") %>&cadd1=<%= Request.QueryString("cadd1") %>&cadd2=<%= Request.QueryString("cadd2") %>&cplace=<%=...
4
by: KathyB | last post by:
Hi. I have an hmtl page with a function to see if there are any input text boxes. If so, that means a user did not complete them (once entered, my xsl stylesheet makes them text instead of text...
19
by: Pete | last post by:
I have form/select which executes a function using onchange. No problem. However, when I validate the page with a strict HTML 4.01 doctype at http://validator.w3.org, it demands either an action or...
1
by: lion | last post by:
my Problem: a query string passed into a html page doesn't display correctly on a mac I am just using html and javascript (no ASP, PHP or server side scripting) This is the query string:...
4
by: Raterus | last post by:
Howdy, Simple question, but I can't figure out how to do it. I have a a page which is called initially with a querystring. After I get the querystring values, I don't need the querystring to...
12
by: Alex | last post by:
I have a question about determining if one QueryString keys exists. The idea is, if this key exists, than its presence is enough to indicate that its value is true. For example ... ...
3
by: Dan Sikorsky | last post by:
How can I get the Querystring passed to the Referring Page from its referrer? I don't want the querystring coming to my current page. I want the querystring that came to the referring page, so...
2
by: Jassim Rahma | last post by:
I have an ID which I pass from the QueryString. The id is integer only and I want before performing any action to validate if the Id is valid integet.
3
by: pingsheng | last post by:
Dear all, I have a form with dynamically created input fields. These fields go to next page for submitting into SQL database. The thing is all fields are the same but 4 fields. So each record...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.