I have a asp.net page that has a button to click. When click on it, I wish to have a querystring such as ?id=1 added after the normal url. How can I do that from server side c# code?
|
Three ways... server-side redirect, LinkButton, and client-side button or link. You can have your button event handler redirect to a location with a querystring...
You can render the button as a LinkButton and set the URL...
Or, you can render the button as a client side link - this is what I do when using Repeater controls...
I prefer the last method, particularly when I need a whole bunch of links. BTW, this is application of KISS - all you need is a regular old link, you don't need to jump through server-side hoops to create a link with a querystring in it. Using regular client-side HTML whenever possible is how to keep ASP.Net simple. I don't see enough of that technique in the wild. |
||||
|
There are various way to add querystring in url. You can use following code If you want to add value on server side:
|
|||
|
How to build a query string for a URL in C#? or string url = Request.Url.GetLeftPart(UriPartial.Path); url += (Request.QueryString.ToString() == "" ) ? "?pagenum=1" : "?" + Request.QueryString.ToString() + "&pagenum=1"; |
|||
|