Ye Myat Aung
Ye Myat Aung

Reputation: 1853

How to receive values passed to ASP.NET page with HTTP GET?

I'm trying to receive the values passed from other non aspx page to my asp.net page with C# via HTTP GET with Parameters. Would it be fine if I fetch the values with Request.QueryString in Page Load event?

Please advice.

Here's what I've done so far.

protected void Page_Load(object sender, EventArgs e)
    {


        //fetch query from url
        string queryTimeStamp = Request.QueryString["t"];
        Int64 queryCallerID = Convert.ToInt64(Request.QueryString["s"]);
        int querySMSGateway = Convert.ToInt32(Request.QueryString["d"]);
        string querySMSMessage = Request.QueryString["m"];

        //Do other processings
}

Upvotes: 1

Views: 1175

Answers (2)

Elias Hossain
Elias Hossain

Reputation: 4469

Below is the better way to go, which will handle unexpected exception, thanks:

string queryTimeStamp = Request.QueryString["t"];
Int64 queryCallerID;
Int64.TryParse(Request.QueryString["s"] == string.Empty ? "0" : Request.QueryString["s"], out queryCallerID);
int querySMSGateway;
Int32.TryParse(Request.QueryString["d"] == string.Empty ? "0" : Request.QueryString["d"], out querySMSGateway);
string querySMSMessage = Request.QueryString["m"];

Upvotes: 2

Pranay Rana
Pranay Rana

Reputation: 176906

you can get the value in Request.QueryString or Request.Form collection

Upvotes: 4

Related Questions