Count the number of parameters of a query string in asp.net using c#

In this programming tutorial you will learn how to count the number of parameters of a query string in asp.net using c#. Some times you may wanted to know how many parameters your query string contains so that you can implement appropriate checks in your code according to your requirement. In asp.net finding parameters are quite easy. Let's have a look over the code snippet given below

Count the number of parameters in a query string
protected void Page_Load(object sender, EventArgs e)
    {
       
        Int16 totalParameters;
        if (!Page.IsPostBack)
        {
            totalParameters = Request.QueryString.AllKeys.Length;
            Response.Write("The number of parameters the query string contains are "+totalParameters);
        }
     }

So that's it. The Request.QueryString.AllKeys.Length will give you what you want.
I love your feedback.

0 comments: