blog.x-e.ro / post and querystring vars in dotnet : asp.net c#

post and querystring vars in dotnet

c-sharp :: asp.net c#

here's a nice little snip of c# code. this is meant to be used in an asp.net web application. the following code will return either a querystring variable or a post variable, it tries both and finds the valid one.

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();
}
loading...

loading...