In my previous tutorials, I’d explained passing datatable as storedprocedure parameter in asp.net, get gridview selected row hiddenfield value using jquery, exporting gridview data to word excel text and pdf and other more cracking tutorials on GridView, Asp.net here.
I already explained how to pass querystring with multiple parameters in asp.net here.
As you know that passing &(ampersand) in querystring is not allowed because ampersand is used as a separator to pass multiple parameters within query string url. Its OK when your query string url doesn’t contains & (ampersand) in a query string parameter value but what happened if you are passing &(ampersand) in querystring?
It cut off the contains value after the & (ampersand) of a specific key variable. For Example, If you pass the value like desig=R&D Expert then the value for the design will be shown as R instead R&D Expert.
To resolve above error, we need to use Server.UrlEncode() method as following example.
Passing &(ampersand) in QueryString Using C# or Vb.net – [.cs/.vb]
If you are using C# as code-behind, use the following code:
Response.Redirect("Page2.aspx?id=" + txtId.Text + "&name=" + txtName.Text + "&desig=" + Server.UrlEncode(txtDesig.Text));
If you are using Vb.net as code-behind, use the following code:
Response.Redirect("Page2.aspx?id=" & txtId.Text & "&name=" & txtName.Text & "&desig=" & Server.UrlEncode(txtDesig.Text))
As you can see from the above example, I used Server.UrlEncode() method to encode the & (ampersand) within query string value for both c# and vb.net example.
As you can see from the above example, I encoded & (ampersand) as %26 to escape the & (ampersand) within query string parameter value.
How to pass Multiple Parameters within QueryString?
You can learn more about how pass multiple parameters within a querystring url here.
You can learn more about how to get querystring parameter value from client-side using jquery here.