I am having a listview and binding it with items retrieving from database. I have used pager to navigate to various page. But problem is that suppose currently I am in page number 25 and refreshed the page by hitting F5 or clicking on the browser refresh button, it will redirect me to the page number 1. I mean to the first page. But I want after refreshing also it should be in the current page I mean in page 25. I am not getting why it is happening.
It is better to add a querystring with the current pagenumber. for eg Consider your page is a.aspx and just pass an querystring like this a.aspx?pg=1.
On the page load if(Request.QueryString["pg"]!=null) then just display the records of page 1. Suppose if you want to show at 25th page then url will be like this: a.aspx?pg=25.So if a user refreshing by F5 it will still displays the same data.If the page has undergone postback (due to button click event or dropdownlist selected index changed etc) it also displays the same record because of Querystring. You can also change the pagenumber by redirecting it to same page with another value in querystring Eg:Response.Redirect("a.aspx?pg=26").
I think this will solve your problem.
If you are programatically binding on the page load event, this will happen. You could set a session variable when the user changes page and manage this in the page load event too.
Related
I'll keep this simple. I have two pages:
List page
Detail page
Quick info on the list page:
A grid to show list of items with a "view" hyperlink each pointing to the detail page (e.g. detail.aspx?id=1)
A number of filters and a search button
By default the list shows all items without any filtering
Scenario 1 (OK):
Without any filtering, click on any of the view links
This will take me to the detail page of the selected item
Click on the browser back button, the list page is shown (OK)
Scenario 2 (Not OK):
Do a search filter on the list page, this triggers a postback with filtered items
Click on one of the view links
This will take me to the detail page of the selected item
Click on the browser back button, ERROR PAGE!
Error info:
IE: Webpage has expired
Chrome: ERR_CACHE_MISS
Firefox: Document expired
Any idea why scenario 2 fails to bring up the list page? I don't need the filters to be retained when going back, I just need the list page displayed straight away without the error.
Thanks in advance
Try to clear the cache. Here is a similar discussion.
But what I did was to disable the back button with a line of Javascript to prevent these kind of problems
<script type="text/javascript">
history.forward();
</script>
And I inserted a "Back" or "Return" button into the second page which will be used to go back to the initial page.
I hope this is convenient for you.
I've two text boxes in one page and after those text boxes two separate search buttons, search buttons redirect to another page where user searchs and result is displayed in a grid, there can be multiple results, each row of grid contains 'select' command so that when user clicks on select of perticular row its data is selected and page redirects to previous page and data of row is displayed in textbox..
I've done so far. This is what I want to do:
Since there are two textboxes, two separate search buttons, what I am experiencing is when user selects 1st data for 1st textbox and searchs for 2nd text box then while returning for 1st page after 2nd search, 1st textbox becomes empty, What I want is that it should contain the value user has entered before.
textboxes should keep the value. If searching for 1st text box then 2nd should keep its value and if searching for 2nd text box 1st should keep its value.
I am using response.redirect method in dg_RowCommand event. I think by this page is rendering with its initial values which is what I don't want.
kindly tell me the solution I have searched so much but came up with nothing.
You can store the values in either Cookie or in a Session variable. Session variable is application specific and cookies are browser specific.
try this, for creating a session variable
Session["key"] = "your value"
or
for Cookie
Response.Cookies["key"].Value ="your value"
on the another page check first is it not null
if(Session["key"]!=null)
// use it
and same for the cookie (access it with Request object)
if (Request.Cookies["key"] != null)
// use it
use Session variable. Session["YourKey"] = your value; You can access it cross page
Update:
If I am right then you are thinking of some wizard type interface. If you can take benefit of ASP.Net Wizard control then look into this. It might help you.
Combine the pages into one, with each page(step) becoming a div or asp:Panel. hide/show divs rather than "navigate to the next page" on Click_Next event (or whatever). This way all controls stay on the same page and maintain all values when the divs are shown/hidden. No Session or other methods needed.
If you are redirecting with the Response.Redirect method in the C# Code then before you execute this redirect you can store the items in Session variables:
Session["Test1"] = test1.Text;
Sessions are maintained per user. These will be retained for as long as the application is running, but be warned that if an Application timeout occurs or the user closes the application (closes browser) these values will be lost.
Im having an issue of going back to the previous page. The page i want to go back to had a few radio buttons which you had to select, after this you went to the next page which is the current page which then you can select certain things BUT I want to be able to go back to the previous page and the original selections for that page still be selected.
Anyway i could do this if so how?????
You can do a real basic back button with the help of JavaScript.
window.history.go(-1);
which will take you back to the previous page.
By default in ASP.NET state of controls is stored in ViewState, so it should be the same as user left them.
It is probably some view-state issue.
Go to your codebehind and check PageLoad method. If you are creating or setting radios in PageLoad, you do not want to re-init them every post-back.
if (!IsPostBack){
// your init here
}
In my webpage, there is a repeater control which holds an image and its description. After the page is been loaded, the user can reorder the images(Jquery is used for reordering divs).
After the reordering, if the user refresh the page or click any button, the page will go back to the previous state before reordering.
How can I prevent this.
The repeater control is in .aspx page.
Thank you in advance.
If the page is refreshed there's nothing really you can do. The browser will send the same request you sent before.
Because the sorting is done client side, you should save it states somewhere and then you can request again the page to the server.
So for instance, let say that you order your repeater by the "CreatedDate" column. Once ordered, you can save the column name of the ordering in a hidden field. Once you click a button, the page is loaded again and you step in the page load event in the code behind.
At that point you can get the value of the hiddenfield posted, you will find that it got "CreatedDate" as a value. You can then return the datasource for your repeater already ordered by date and the user will have the same view he had before posting the page.
I have two pages.
In one page I have placed a GridView. In the grid I am using two hyperlinks for select and edit. When I click for the edit page I am redirected to another page. When I have finished editing the record it goes back to the first page.
The problem is when I was on the 2nd or 3rd page of the GridView and then edited, it went back to first page, not the 2nd or 3rd page I was on.
I want the same page after I go back to the page I left. How can I go about this?
The problem is that the webpage needs to know what page to send you to. The way I do this is to pass a querystring parameter when I change pages.
So in the URL to the edit page you want to have the URL say (for example) http://server/edit.aspx?value=number&returnPage=2 and then when you go back to the grid page you'll pass the page value like http://server/grid.aspx?page=2
This way you'll always know what page to tell the GridView to goto. And it should be pretty easy to add in depending on your level of comfort with the Params object.
Response.Redirect("einward.aspx");
you have to redirect to the page, wtever page u want.