views:

203

answers:

5

HI, I need to remove a querystring when a user clicks a particular LinkButton. So for example if the querystring is http://UserProfileManager.com?UserID=1234 .... when the user clicks on the Linkbutton, I want the url to be http://UserProfileManager.com. The issue is that everything is on one page, and I am using asp:panel to show and hide different areas of the webpage.

Any ideas would be appreciated.

A: 

Look at the request object - while I can't remember the exact properties, there are ones line scheme (which would return "http://") - there will be one, or a combination that will give you what you require.

Further research - look at the Request.Url property. Then strip off the query string. I couldn't see an exact method in the uri / uricomponent classes to give you exactly what you are looking for, but it shouldn't be that hard.

Ken Ray
A: 

On page load you could extract the query string to a hidden text box.

When the user clicks the button clear the text box

If the user navigates away use the string in the text box and append the query string to the URL.

I hope this helps Sp

Steven
A: 

Actually I would ask why you are doing this?

Are you using querystring parameters to store data?

Fishcake
querystring is used to allow user to EDIT a record. Should the user decide not to edit, but instead go back to the "lookup" section, I need to eliminate the querystring
user279521
A: 

hey,

you cant actually remove a querystring from the URL. I mean to say that there is no .remove() method available for that. If you still want to do so you will have to use the .substring() method and get it done manually.

Just a tip that may prove helpful: If you are using the QueryString values to maintain different states on the same page then i would rather suggest you to keep those values in a ViewState on the page and make changes to it accordingly. This way your URL will remain clean, users wont be able to harm your flow and will work just fine.

take care!

Shrewd Demon
that is a dag gumm good idea.
user279521
+2  A: 

You have several options:

1) In your code behind, just set the LinkButton's URL to the shorter address if the querystring contains a "UserID" key:

if (Request.QueryString["UserID"] != null) {
    this.LinkButton.PostBackUrl = "http://UserProfileManager.com";
} else {
    // other address
}

2) Send the UserID in a hidden field instead of the querystring.

3) Separate your view and edit pages - putting everything in one *.aspx is probably going to cause more trouble than it's worth down the road.

Jeff Sternal
I would like to send the UserID in a hidden field, but the user selects the record to edit from a gridview (edit is a hyperlink), where I have a DataNavigateUrlFields value set to UserID and DataNavigateUrlFormatString setting the querystring. How can I handle setting UserID to a hidden field in a gridView?
user279521
It's pretty hard to untangle one's self from the `GridView` control - it's usually in for a penny, in for a pound. Since that's the case here, I recommend using either option 1 or 3.
Jeff Sternal
option 1 worked. However, it required setting the url in the LinkButton's property window; Thanks very much.
user279521