update gridview and go back to the previous page - asp.net

I have a gridview, getting data from sql server, there is an Edit link to get the detailed information for example, for a user from database.
this link open a new page with detailed information and when I click the updated button,I want to go back to the same page with that users informaton.
I set the page size to 10, it means I can see only 10 users per page,and if I click the edit link on page 25,and update the users info, I want to go back to page 25.
Should I use viewstate or gridview has any commnad to go back to the same page? the code is written in ASP.net C# sqlserver,
Thanks in advance

The gridview control will not provide this functionality.
Viewstate will only help persist data between postbacks of the same page (primarily).
Session state could be used to save the pagesize/pagenumber details onclick of the grideview edit before forwarding to the edit page. This can be re-processed back on loading of the view page.
My preference would be to store the values in the querystring. So on clicking edit, the pagesize and number are passed to the edit page (i.e edit.aspx?itemid=1&psize=10&pindx=25).
Then on finishing edit, the page number and size are based back to the view page for processing (view.aspx?psize=10&pindx=25)

Related

Clear form data while pressing browser back button in asp.net

I have a web form (page 1) which gets the input from the user and stores in database.
When I click save, after saving the data, it displays a message with application id in a new page (page 2).
If I click back button through browser, then it is going to that page 1 and displaying the input that I have given.
I want to prevent this. I disabled cache of the page 1, but when I click back this time I am getting web page has expired in IE.
But sometimes it is going to the previous page (page 1) and displaying input fields without a data.
Can anyone please help me how to fix this?

Timer and gridview

I want to display a online user indication in image item template of gridview inside a update panel which triggers by a timer in a certain time period. The image item template is getting image from a generic handler (.ashx) using a sql server database. the gridview is getting data from another sql server table which is inside an update panel as mentioned earlier. the problem is- when i login the main page from different browser (IE, Firefox,Chrome) in same pc the first browser which i login first, it is not displaying the latest user online indication. What should i do??? Plz help me.

Return to same page state in ASP Web Pages (WebGrid)

I have created a page in ASP Web Pages with WebMatrix, where I use a WebGrid with paging to show the data from a query. I also have a search form on the top to search though the database. The rows are clickable, and when clicked it goes to a details page for that row, but when I go back, the WebGrid is reset. Is there any way to save the state of the webgrid, and eventually the filled search forms if they have been used, when I go back? It seems to me that when I just go back, without refresh, the page doesn't query the database again, because it is faster than refreshing. But the WebGrid is reset anyway to the first gridpage.
Can someone help?
I also noticed that WebGrid to go to its other pages. Does it retrieve all rows in the beginning or everytime in paging?

Force ASP.NET controls to reload data

I know there's a lot of information out there about how disabling ViewState will not prevent textboxes from persisting values across refreshes/postbacks. What I can't fins is information about how to circumvent this behavior.
Here's why I need to do this. I have a form that updates a db via AJAX. Every time a user changes a field, the db is updated immediately. Because of this, there's no reason to store values anywhere but the database.
Consider the following scenario.
User loads the page, textbox FirstName has a value of "Bob."
User changes first name to "Dave." (Database updates)
User clicks the refresh button.
We'd expect the FirstName box to now have the value of "Dave," but instead it shows "Bob." So how to force ASP to load the values from the db?
User clicks the refresh button.
On this step you'd re-read the data from the database and forcibly populate the controls with that data. If all of the "events" from the page are in fact handled by AJAX requests, then it sounds like the only two meaningful "WebForms events" are Page_Load and the Click handler for the "refresh" button. One of those two events should re-populate the controls from the database.
(Or is there no "refresh" button and the user is just reloading the page via browser functionality? In which case Page_Load should just always populate the controls from the database in this scenario.)
It seems the problem I was encountering had to do with creating and populating controls in during the correct page events. Fixed this by creating controls in Page_Init, and populating them in Page_Load.

Automatic page refresh even we navigate to another page

i have a problem in page navigating. please help me to solve out.
in one asp.net page forexample Page1.aspx i have dropdown when we select an item in dropdown that would display in a label. Then we navigate to another page from page1.aspx to page2.aspx by clicking linkbutton in page1.aspx. Again if i come to page1.aspx that previously selected value of dropdown should appear in label.
please help me.
HTTP is a stateless protocol. This means that it'll forget anything that you don't tell it to specifically ask it to.
When going back to Page1.aspx, your program has no idea what was selected before.
In terms of persisting user choices, you should look into storing them in Session ( or alternatively, cookies ) and checking for a pre-existing choice when returning to Page1.aspx.
If you have a saved value for the user at that point, you'll be able to set the correct value during the Page_Load event.
If it is like a wizard, I suggest you use a wizard control in the same page.
here is an example,
https://web.archive.org/web/20211020103244/https://www.4guysfromrolla.com/articles/061406-1.aspx

Resources