Remove GET variables on URL when doing a submit - c#

I have this problem: I have a page with a datagrid with links that redirect to the same page, adding variables to the URL. Once the user chooses some options in the form, it submits, once again, to itself.
My issue is that I must remove all those variables in the URL or they disrupt the submit. Any way to clean the URL while doing the POST?

No, the POST will happen with the current querystring.
You could add the querystring parameters to Session and negate the need to pass this in via the URL.

Solved it. Just need to add a PostBackUrl to the button. Sorry if it was a dumb question.

Related

Is that possible to append the querystring in the controller for MVC

I'm trying to append values to the URL in the server side action. Is that possible? Looks like we have to do that from the browser side when submit the request. Is there an generic way to add querystring to the URL?
Yes it is possible ...
Use JavaScript to append the selected value to the domain before it submits. Change the button to have an onclick attribute as oppose to making it submit the form.
Add this JavaScript to your head section (or wherever you want, but convention is typically the HEAD section or bottom of the body)

ASP.NET Web Forms - How to redirect and pass parameters without problems

I wanted to redirect (by code) to another ASPX page and on that page I wanted to select the appropriate view (in a multi-view and during page load).
My solution was to add a url parameter that was checked on the "OnLoadComplete" event and take appropriate action, but it seems that this url parameter gets copied to all the links on the page. So, the user cannot navigate anywhere else because always this view gets presented.
My second thought was to use a Session variable, but I am afraid that this will be an overkill.
Any ideas/thoughts/suggestions on this matter?
Can I prevent the use of the url parameter in all the page-links?
Is it bad if I use a Session variable for this temporarily?
Is there some other way to do this?

Passing Hidden Fields to another aspx page

I want to be able to pass data from one aspx page to another using hidden fields.
On pageone.aspx, in the page_load, I am saving data into a hidden field:
ClientScript.RegisterHiddenField("var1", "hello");
Then, the user clicks on a button on pageone.aspx, which redirects to pagetwo.aspx
Response.Redirect(Constant.AdminUser, true);
Then, in the page_load of pagetwo.aspx, I grab pageone's hiddenfield by:
Request.Params["var1"]
But nothing is returned.
For some reason, when I replace Response.Redirect with Server.Transfer, I get data in pagetwo.aspx, which is what I want. But the browser's URL does not change.
I want to be able to pass in data from pageone to pagetwo, without storing the data in the session variable, url, database, cache, etc. I would like to send it using hidden field.
MSDN has a full article on handling cross-page posting.
http://msdn.microsoft.com/en-us/library/ms178139.aspx
TL;DR: You have to register the previous page using the #PreviousPageType declaration, then call against the PreviousPage property.
I do something very similiar and all I did was erasing my Server.Transfer line and keep PostBackUrl on my button.
If you have them both, your URL won't change.

Postbackurl Vs Response.Redirect (losing data)

I have a button in my aspx page, which in code behind the value of postbackurl gets set. I updated the code to add click event handler and added Response.Redirect code to redirect user to the page once the button is clicked. The only reason i ended up adding click event was because i had to add some extra logic when the button was clicked including redirecting to same url, that was used in postbackurl. The page does get redirected on click however it seems like all the hidden fields from the field gets lost once the form get redirected to the url.
Is there anyway i can submit the form without loosing the hidden data.?
Maybe one way you can solve this problem is to use the server side Transfer() call.
http://msdn.microsoft.com/en-us/library/540y83hx(v=vs.85).aspx
In most cases I've seen what you really want to do is pass the information for the new page using URL parameters. Take all the stuff the new page needs and put it into the url (encrypt if it is security sensitive).
If the only issue you are having is when you want to stay on the same page, this is simple, just have the click event handler return without doing a response.redirect or a transfer.
Post the code if this is not working for you.

Context rewritepath problem with form C#

i have a problem when i RewritePath in HttpContext,
context.RewritePath(Utility.WebRoot + "List/Add.aspx", false);
It work fine to rewrite the url: http://localhost/List/Add
But when i hit the button it redirect me to http://localhost/List/Add.aspx
Is there a good way to "stop" the redirection to the .aspx page and just leave it on http://localhost/List/Add ?
Thanks for help
There is an issue with the From tag. You have to use a Control Adapter like this one:
http://weblogs.asp.net/scottgu/archive/2007/02/26/tip-trick-url-rewriting-with-asp-net.aspx
Go to the "Handling ASP.NET PostBacks with URL Rewriting" section.
This will help:
http://www.codeproject.com/KB/aspnet/SmartFormControl.aspx
Basically the idea is to create a new Form control (I called my "ActionlessFormControl") that derives from the .Net Form control. The gist of it is that you override the rendering of the attributes and set your own value for the "action" attribute. What I do in mine is I remove the "action" attribute altogether which will post back to the same URL. Meaning, your page will post back to "/List/Add".
The benefit from using the inherited control is that you don't have to "register" each page. This will allow you to have dynamic content/URLS post back correctly.

Categories

Resources