Why not use some helper functions like this?
private T LoadRequiredRequestParam<T>(string ParamName) where T : struct
{
try
{
return (T)Convert.ChangeType(Request.Params[ParamName], typeof(T));
}
catch
{
Response.Redirect("/default.aspx");
return default(T);
}
}
private T LoadOptionalRequestParam<T>(string ParamName, T DefaultValue) where T : struct
{
try
{
return (T)Convert.ChangeType(Request.Params[ParamName], typeof(T));
}
catch
{
return DefaultValue;
}
}
Their usage is rather simple:
int PageID = LoadRequiredRequestParam<int>("pageid");
int PageNumber = LoadOptionalRequestParam("pagenumber", 1);
P.S. I did not test it, just compiled.