Haider Khattak Haider Khattak - 2 months ago 10
ASP.NET (C#) Question

Method for querystring not returning value

I am passing some value from one page to another page via query string, it passes the values correctly and then passes to the stored procedure succesfully but typing the

Request.QueryString["something"]
again and again is very irritating, so I created a method for it, but the method does not return/passes any value and the nullreference exception is thrown.

protected void Page_Load(object sender, EventArgs e)
{
try
{
using (Property_dbDataContext context = new Property_dbDataContext())
{
_errMsg.Enabled = false;
_errMsg.Visible = false;

var find_prop = context.find_property(val("city"), val("type"), val("subtype"), val("bedrooms"), val("size_unit"), Convert.ToInt32(val("area_from")), Convert.ToInt32(val("areato")), Convert.ToInt32(val("pricefrom")), Convert.ToInt32(val("priceto"))).ToList();
//code above does not return any value

//var find_prop = context.find_property(Request.QueryString["city"], Request.QueryString["type"], Request.QueryString["subtype"], Request.QueryString["bedrooms"], Request.QueryString["size_unit"], Convert.ToInt32(Request.QueryString["area_from"]), Convert.ToInt32(Request.QueryString["areato"]), Convert.ToInt32(Request.QueryString["pricefrom"]), Convert.ToInt32(Request.QueryString["priceto"])).ToList();
//code above return value from the database but its a long procedure

rptr_properties.DataSource = find_prop;
rptr_properties.DataBind();
}
}
catch(Exception ex)
{
_errMsg.Enabled = true;
_errMsg.Visible = true;
_errMsg.Text = "Sorry! Property not found." + ex;
}
}

public string val(string a)
{
return Request.QueryString["" + a + ""].ToString();
}

Answer
    This will work
    public string val(string a)
    {
        return Request.QueryString[a];
    }