Get previous webpage - c#

I am at a loss as to how this is best handled in asp.net
I have a webpage with a lot of panels, and tables that is populated with data from mysql request. Now this data might change depending on an input. All the data are buttons that will open a modal windows displaying data.
My issue is that when I press the button the modal opens, but all the tables are reset to the standard "sql data" and the panels collapses. I basiclly want to be able to post back to the exact spot the user was earlier, including where on the page he had scrolled.
I get that the created html istanse is destroyed as soon as the person moved to the modal but how can i store the current exact state of the webpage so when the user goes back he is met with the exact "copy" he left. I've looked into viewstate and state management, and also to check for postback but still havent been able to solve it.
Is there any good tutorial covering this topic?
I've looked into this: Persisiting the state of a webpage
But thats based on ASP2.0 (im at 4.5) and dated 2006. Would this approach still be my best option or is this fixed in a better way on newer ASP.NET version?

Related

asp.net web form in multiple browser tabs

I have a grid view and an edit button in the grid view. On edit button click I am opening a new aspx page that has text fields for input the data. When a user copies the URL of the gridview and opens it in a new tab of any browser then click on the edit button for two different records. If the user changes anything in the first tab and submits it. It changes the info for the record on the second tab. It is happening because I am passing userid in session to the form aspx page and session got updated when user opens the second record in the new tab.
Are there only two ways to passing data to aspx page?
using session
using a query string
I don't want to use the query string.
Please help thank you.
You are writing a ASP.Net application, so at the end of the day there is only that much you can do. You can request some things off the browser, but if he actually does it is entirely up to it.
You can make it unlikely to happen by accident, using the HTML Links target property. This requests the browser to re-use any alread open tabs for this record. But that will not prevent a dedicated person from still opening 2 copies.
A pretty simple way to avoid race conditions in general, is the SQL rowversion column. You retreive the rowversion with the rest. You keep it along in a hidden formular field (that is what they are there for). When writing the update, check if it still matches before the write. If yes, you update. If not, somebody has modified the record since then and you reject the update. Can be the same user in another tab, can be another user at the end of the world. Could be that this tab was opened a year ago, surviving on sleep mode. It does not mater - any change trips this protection.

ASP.NET WebForms, DropDowns, Submit Button

I have struggled to find a solution to this problem through lots of Google searching and documentation reading, and even looking at others’ source code, but I am putting it here in the hopes that someone knows how to help me or has specific experience in dealing with such a thing.
I am currently working on an ASP.NET WebForms project with some of my colleagues, and we have decided to go with an option of which I was not a fan. We have created a page where the user will be required to fill out the university classes they have taken, with related data, in a massive sheet of dropdown menus.
These dropdown menus are pulling their associated data for the user to choose from the database (SQL Server, a.k.a. “Microsoft SQL”), as a way to partially limit user error. The user will make their selections on none, one, some, or multiple dropdowns from multiple “rows” on this page.
My question is how I can write an SQL Server query, and thus, stored procedure, that will allow for a “submit” or “save changes” button to be added to this page. When a user clicks this button, presumably, all of the changes that they have made on any of these “rows” – one row per class – will be added to the database for their respective user account.
My suggestion was having that page be an ASP.NET Grid View that would update with the classes that the user had taken as they entered them. There would be a button at the top of the page where the user could click “Add Class”, and they would be taken to a model popup or some other page, and they would enter the details of that class, mostly through predefined information that is pulled from the database. In the case of an administrator user, they would essentially be able to put whatever information in for the class, because they have the ability to override the strictly regulated format for regular (student) users.

How to display multiple pages under tabs similar to a Browser tab retaining loaded pages

We have an application where we have a single level navigation menu with some heavy-duty pages on each link. The user can switch back and forth between these pages frequently to obtain information that he needs.
Once the page gets generated, it wouldn't change for the session. However, the page is specific to the user, hence we cant cache it.
I was trying to come up with a solution where we generate the page once, and keep it hidden in the background until its link is clicked, but haven't been able to get my head around this.
One of the ways I thought was to have multiple div tags (one for each page) on one page and keep toggling the visibility as the links are pressed, but that would end up making this single page very heavy. Someone also suggested using iFrames, but I am not really comfortable using the iFrames much and I'm not even sure, if it would be any helpful either.
Can you guys please suggest a few approaches to tackle the issue?
update: Just to clarify, we are fine with keeping the pages separate and navigate across using a standard menu bar. We were just looking for ways to optimize the performance as we know that the pages once generated wouldn't change and there should be some way to tap that benefit.
You can use Ajax tab control for this purpose
Try taking a look at this MSDN article which specifically tackles the issue of how to user-level cache. Also, it might be more manageable to break each tab into a user control. That way your ASP.NET page has just the tab control and 1 user control for each section under the tab. It makes managing tabs much easier.
EDIT:
What I would do in your case, since you say the data won't change for the user, is I would grab the static data from the database and then I would store that data in the Session cache. THe session cache is specific per user and you can try to retrieve the static data from there instead of repetitively calling the database.
Check out the ASP Multiview control. Just remember that even though the different views are hidden when not active, their viewstate is still being sent back and forth. Can be a benefit if you need to check control values across views though.

What are the MUSTS for having an asp.Net application to support BACK button of the browser?

Is there any pattern or kind of "least requirements list" to follow for ensuring an asp.NET application to support BACK button of the browser for each aspx page?
thanks
In general, the back button on the browser will take you to the previous HTML GET or POST that occurred. It navigates by page-wide transactions, so anything done dynamically cannot be navigated that way. Also, the back button doesn't rewind code execution, so if you are determining something based off of a Session variable or something similar, that won't be rewound either. Obviously, it won't rewind database transactions either.
In general, if you want to support the back button, you'll need to make sure to divide everything you need to navigate between with said button is divided by an HTML transaction of some sort.
Again, you're going to run into issues if your page display is dependent on server-side control that changes from one post to the next. This is one reason you see some forms feed a 'Page has expired' error when you try to navigate back to them.
Not really... It depends on your application flow.
There are things that make supporting the back button more awkward.
for example using pure ajax to change the majority of the content on the page,
will look like a 'new' page but wont be compatible with the back button (though you can fudge it)
another example is posting back to the same page more than once, as this can make it appear like the back button is not working, and at the same time re-doing your request (and therefore database transactions)
Fundamentally it depends on your application requirements.

Display gridview in new window

Just a bit of advice needed really in terms of how I should handle my current scenario:
I have a web page that searches for products/category information the results of which are at present displayed in a gridview on the same page.
However, said gridview is a bit of a beast and as such, I would like to have a page that the user searches for, a button is pressed and the subsequent gridview is displayed in a new window.
Ultimately, I would like the user to be able to make multiple searches so that new windows can have multiple gridviews containing different data sets.
My current thinking is to create session variables that can be pulled through onto 'the gridview page'. Having said that, I'm not sure that would work if multiple searches are created?
I am also thinking I might be able to create said 'gridview window' using javascript but my concern here is the potential loss of functionality of the gridview i.e. paging, sorting, editing, etc.
Does anyone have any thoughts or theories on this? What would be "best practise"? Any thoughts greatly appreciated and taken on board.
PS: This is being developed in .net, using c# and LINQ.
PPS: I'm a noob so be gentle!!
There is no need of sessions here right ? well on your first page where you enter search query, when user clicks on the button open the search result page in a new window with a query string may be search.aspx?keyword=foo.
so everytime user clicks on search button it keeps on opening new windows. u can javascript to open the new popup window and set "target" attribute to "Blank" so it will open in new window

Categories