Click here to Skip to main content
13,861,916 members
Click here to Skip to main content
Add your own
alternative version


21 bookmarked
Posted 8 Mar 2006

Request Query String / Form Parametrs

, 8 Mar 2006
Rate this:
Please Sign up or sign in to vote.
Request Query String / Form Parametrs Reducing Server Load
<!-- Article Starts - DO NOT ADD HTML/BODY START TAGS-->


Most of beginners developers that program in ASP or ASP.NET use Request object.
Usually they use it in the form of Request["Parametr_Name"] , while not taking into account the fact
that this way of using the object causes a great load on the server performing this task.
Meaning that the server load into memory the whole Request object collection and has to decide weather to activate
the Request.Form or Request.QueryString methods.

When the site serves a great number of users this can cause a great load on the server.

In this article I'll present a simple way to ease up the server load.

Using the code

In the code below I first check the Request.Form.Count if it's greater then zero,
then method="post" was used, and I read the given ParamName , ELSE
I check if Request.QueryString.Count is greater the zero and only then I decide if to read the parameter.
IF the result is null I turn it into String.Empty in This way I don't have to check if the value is null and only
then get it's ToString() method to convert it into string and then check it's value.

public string RequestParam(string ParamName)
    string Result = String.Empty;
    if (Context.Request.Form.Count != 0)
        Result = Convert.ToString(Context.Request.Form[ParamName]);
    else if (Context.Request.QueryString.Count != 0)
        Result = Convert.ToString(Context.Request.QueryString[ParamName]);

    return (Result==null) ? String.Empty : Result.Trim();

So when I use the above code I can do the following:

if (RequestParam("ZipCode").Length < 5)
    ErrorMesage = "Zip code must contain 5 numeric digits.");
In the "Old Way" you could not write if (Request["ZipCode"].ToString().Length <5) because if Request["ZipCode"] == null
it does not have a ToString() method.

Using the code above enables me to use the Request Parameters as a string and saves me writing code to determine if it's null.


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Leon Kovach
Web Developer
Israel Israel
No Biography provided

You may also be interested in...

Comments and Discussions

Questionmmm... are you sure? Pin
Cradle778-Mar-06 9:02
memberCradle778-Mar-06 9:02 
AnswerRe: mmm... are you sure? Pin
Leon Kovach8-Mar-06 23:14
memberLeon Kovach8-Mar-06 23:14 
GeneralRe: mmm... are you sure? Pin
Cradle778-Mar-06 23:48
memberCradle778-Mar-06 23:48 
GeneralGood Insight Pin
Prasad Khandekar8-Mar-06 6:53
professionalPrasad Khandekar8-Mar-06 6:53 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web06 | 2.8.190214.1 | Last Updated 8 Mar 2006
Article Copyright 2006 by Leon Kovach
Everything else Copyright © CodeProject, 1999-2019
Layout: fixed | fluid