I have a web page that prompts for user input via DropDownLists in some table cells. When a selection is made the selection replaces the DropDownList so that the action can only be performed once. In the case that a change needs to be made I want to be able to click a button that reloads the page from scratch. I have Googled and Googled but I have not managed to find a way to do this.
Any advice is appreciated.
Regards.
Put a link on the page with the text "Reload" and the url the url of the page. It's perfectly valid to have a page with a link to itself.
If you don't like the link idea, use a standard Button and in the click event, use Response.Redirect to redirect to the current page.
You can set an OnClick for your button that resets each DropDownList's SelectedIndex to 0 instead of reloading the page from scratch. Alternatively, you can set a Response.Redirect([the page's url]) into the OnClick as is suggested here.
Related
I'm very very new to asp.net, and in my tour of its features I found that if you use Server.Transfer instead of Response.Redirect then, among other things, you could preserve the URL of the original page. I created two test pages.
The first has a textbox and a button. When you click the button, the contents of the textbox are saved in the Session variable and Server.Transfer is used to load the second page. On this page there's a button and a label. When you click the button, the label gets populated with what was saved in the session variable.
The issue is, when I click the button on the second page and the label is altered, the URL changes to that of the second page. This seems a bit to defeat the purpose, so how do I go about preserving the URL?
Clicking the button on the second page is causing a postback and the server is showing the URL of the page you are posting back to (the second page). In effect, you have done a Response.Redirect to yourself.
I am curious as to why you want to have two separate .aspx pages behave as if they are only one. One of the major drawbacks of using Server.Transfer is the confusion it causes the user when they think they are on a new page, but the browser says otherwise; especially in bookmarking scenarios.
If you want the logic to reside in a single .aspx page, but act as two separate logical units, then I suggest you use ASP.NET Panel controls that show/hide the logic as needed and the page's code-behind can react to the necessary events (i.e. button clicks) all in one page and the URL will be the same the entire time.
I am using using Response.Redirect to transfer control to another page. but this disables back navigation in the browser. What is alternative way to achieve this ?
Response.Redirect does not disable the back button by any means. Check it using web-console or put debug point on your page and check again. I think in your case the browser back button is working but your page may be forcing it to redirect again to the second page
You can do a client-side redirect.
Here is code for 5 different ways to do this with JavaScript
I recommend the first one which is to set the window.location.href property in JS.
You should use Server.Transfer() instead.
You must have added a javascript function somewhere in your project ( like MasterPage or parent page ) which is disabling back button and which is bad from user point of view , otherwise it isn't possible for browser's back button to get disabled on its own just because you have used response.redirect in your code -behind .
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.
I have a hyperlink on my master page that directs me to the homepage.
It works on every page except a page that has validators.
How do I make the hyperlink work?
More information would be helpful, but I have a suggestion: make sure the hyperlink doesn't have a property called "CausesValidation" = True. A hyperlink control causes a post, which will trigger a validator. Turn it off and you should be good to go.
Ok so while back I asked question Beginner ASP.net question handling url link
I wanted to handle case like this www.blah.com/blah.aspx?day=12&flow=true
I got my answer string r_flag = Request.QueryString["day"];
Then what I did is placed a code in Page_Load()
that basically takes these parameters and if they are not NULL, meaning that they were part of URL.
I filter results based on these parameters.
It works GREAT, happy times.... Except it does not work anymore once you try to go to the link using some other filter.
I have drop down box that allows you to select filters.
I have a button that once clicked should update these selections.
The problem is that Page_Load is called prior to Button_Clicked function and therefore I stay on the same page.
Any ideas how to handle this case.
Once again in case above was confusing.
So I can control behavior of my website by using URL, which I parse in Page_Load()
and using controls that are on the page.
If there is no query in URL it works great (controls) if there is it overrides controls.
Essentially I am trying to find a way how to ignore parsing of url when requests comes from clicking Generate button on the page.
Maybe you can put your querystring parsing code into IsPostBack control if Generate button is the control that only postbacks at your page.
if (!IsPostBack)
{
string r_flag = Request.QueryString["day"];
}
As an alternative way, at client side you can set a hidden field whenever user clicks the Generate button, then you can get it's value to determine if the user clicked the Generate button and then put your logic there.