backward to previous page - asp.net

in my project I have two pages, page1 and page2. In page1 I have few dropdown controls to filter the records from the db. And in the grid view I have the button as "View details". When I click the "view details button, the page has to redirect to page2 and complete details of that record will be viewed.
Now what I need is I have back button in page2. when I click that button, the page has to go back to page1 and page should display like how I left it, should not load as fresh page....
Since beginner to asp.net I couldn't find the solution for this issue.
Please provide with some example....
Very thanks in advance...

Try this in you viewdetails button click event:
Server.Transfer("Page2.aspx")
And similarly in your page2 back button click event
Server.Transfer("Page1.aspx")
The Server.Transfer method also has a second parameter—"preserveForm". If you set this to True, using a statement such as Server.Transfer("Page2.aspx", True), the existing query string and any form variables will still be available to the page you are transferring to.

A simple solution would be to keep any such filters that you have set in session.
This allows you to keep the filters active even when the user navigates away from the page.
You can have a button the Page1 to clear the filters.
Page1 Load:
if(!String.IsNullOrEmpty(Session["Filter1"]))
{
dropDownList1.Text = Session["Filter1"];
}
Page1 dropDownList1_SelectedIndexChanged
Session["Filter1"] = dropDownList1.Text;

Related

Retain previous page field values on browser back button click

My web application has two web pages page 1 and page2. I have a continue button in page 1 to navigate to page2. I enter or select some information in page1 which has textbox, dropdownlist and other controls. And I click on continue button to go to page2. But when i click on browser back button to go to previous page page1 i am loosing all the vlaues in page1. My question is how can i retain the values or information without loosing it. Thank you in advance.
one of the way is to keep those values in the session.
And load it back when you are on the page.

Force a postback when the back button is pressed

I have a webpage with a combo box on the page which is loaded with it's data on the Page_Load event of the page.
From that page I have a link which opens another page (within the same IE window) which allows the user to add/remove items that should appear in the combo.
The problem I have is when the user adds a new item to the combo I need this item to appear in the list on the parent page. However when I click the back button on the browser the Page_Load event on the parent page doesn't fire and the new item isn't loaded into the combo.
Want is the best way to handle this?
I'm using ASP.NET 4.0 and IE9.
Thanks in advance.
You could use javascript and call window.parent.location.refresh() on your new window to force a reload.
Best regards.

How to reaload Dropdown control In this way..please guide

I have 2 aspx pages with C# code behind. Page one have 4 text boxes , one drop down and 2 buttons. Out of 2 buttons one if for appearing the second page as Popup ( as per system requirement. I could use here Ajax popup control , but requirement is different). So my page 2 has text box and button . on click of button of page2 textbox value will go in the database. and page will close. ok ? but same time, dropdown on the page1 should be fill come with fill up the records without refreshing the page1.some how the values in 4 textboxes should be there in textboxes... i tried on my best to elaborate problem.please guide.
You would have to use AJAX to populate the drop down list, which you can do using a web service. Another problem with this is that if you use the standard ASP.NET DropDownList control, and modify the list on the client, you may get an error because the dropdownlist expects the list provided to it from the previous load.
Alternatively, when the user closes page 2, it could call a method on page 1 that calls __doPostBack to force a page postback in page 1, so you could use server code to populate page 1.
A separate page is going to add to the challenges, it would be a lot easier to leverage teh AJAX popup IMHO.
HTH.
Seems like you have 2 pages Page1 and Page2. Clicking on a button from Page1 takes you to a popup page Page2. Then on submit of Page2 you need to refresh DropdownList on Page1 but you need PartialPostback instead of FullPagePostback.
If that is the case. You can javascript to do partialpostback:
http://www.asp.net/%28S%28ywiyuluxr3qb2dfva1z5lgeg%29%29/learn/ajax-videos/video-172.aspx
edit:
To call a method from popup page you need to access method of parent page like: parent.RefreshDropDown();
Reagards.

determining that a Postback opens a new page

I have a page (page1) with a LinkButton that, when clicked, will take the browser to a new page (page2).
When I click the LinkButton page1 posts back and hits the Init and Load event handlers for page1, and then moves on to page2.
How can I tell in the page1 postback that I am about to be taken to a new page, as opposed to clicking a Button that causes the page posts back but does not navigate away?
You can also add OnClick events to your code behind for each button, and in the case of the one that is to postback to another page, do a Response.Redirect. The limitation of that however is that if you need form data on "page2", you will lose posted form data on a Response.Redirect.
It appears that you're not using the OnCLick event of the LinkButton, If you use the event, perform the action of the click there, not on the Page Load event?

Force CascadingDropDown to refresh without page reload

How do I force a CascadingDropDown to refresh it's data without a page refresh? I have a button on the page which adds a variable to the Session which is then used to set the selected value of all the drop downs. However I can't seem to force the refresh of a DropDownList without a full refresh of the page.
Let's see - the button on your page probably has an event associated with it to respond to it being clicked, right?
Can't you just reload and re-assign the data to the dropdown in the button OnClick event?
public void OnButtonClick(.....)
{
.....
CascadingDropDown.DataSource = .......;
CascadingDropDown.DataBind();
}
Or am I missing something?

Resources