Page state is lost while refreshing the page - c#

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.

Related

Browser back button fails - ONLY IF postback has been performed on previous page

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.

Go back to to previous page ASP.NET

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
}

getting some problem with gridview paging

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.

Pager refresh issue

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.

How can I access the value of a checkbox without a postback?

I have a radgrid controlling access to an application for users. There are two columns, a 'name' column and a checkbox 'access' column representing their current access permission. the checkboxes are populated from a database. I would like the to change the checkboxes to grant or deny access to the users I specify. Since there are alot of users I would like to make multiple changes and use a submit button to write the changes to the database. I do not want to postback with each checkbox change and wait for the page to "blink". My problem is that with the checkbox postback disabled, when I click submit, the value of the checkboxes are not registering the changes I make. I need a way to access the current client-side state of the checkbox or some workaround to accomplish this.
Thanks in advance!
You could use javascript to send an ajax request that saves the change to the database without reloading the page. Then your updates happen right away and there's no "blink".
Thank you for the support. It turns out that the issue wasnt with client/server-side visibility, but with the page lifecycle. I was refreshing the radgrid in the PageLoad method and checking the value of the checkboxes in the Submit method. I didn't realize PageLoad was executed prior to Submit, thus clearing my selections. By removing the RadGrid refresh from PageLoad, the current values of the checkboxs were preserved.
If you set AutoPostBack to false, that will disable the postback, but they should still be posting their current values.
Sounds to me more like an issue with the dynamic generation of the checkboxes.
Not sure why you are not able to access the values of checkbox at server side, but to answer your question "I need a way to access the current client-side state of the checkbox or some workaround to accomplish this"...
You can use server tags and read the values of checkboxes at client side.
For more information about server tags, read this MSDN link.

Categories