Showing posts with label query string. Show all posts
Showing posts with label query string. Show all posts

January 09, 2014

Best way to get Query string from url in SharePoint / Asp .Net / webApps



The easiest and well know way is to Request.QueryString[“name”]; but many times to get null exception we should check query string and return in appropriate format. Below I have created a private int variable and protected property of it. You can have a look on below code.


protected int ItemID
        {
            get
            {
                if (Request.QueryString["itemId"] != null && Request.QueryString["itemId"].Length > 0)
                {
                    return Convert.ToInt32(Request.QueryString["itemId"]);
                }
                else return 0;
            }
        }



You can Share your findings or issue or Discussion below.

--
Regards,
Praveen Pandit


June 28, 2013

best way to get string, how to get value from Url C#

How to get Query string value, how to get values from url query with validation and best practice.

public int ItemID
{
get
{
if (Request.QueryString["ID"] != null && Request.QueryString["ID"].Length > 0)
{
return Convert.ToInt32(Request.QueryString["ID"]);
}
else return 0;
}
}



Thanks,
Praveen Pandit
MCTS; MCPD
Keep Sharing Knowledge!!