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.
Related
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.
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?
i want to design a form in asp.net in Wizard style. do something in click next.
the form have 3 step
fill your information
add element [here if you type something wrong then you can edit or delete them before going to next step]
finish
what is the best practise to design this in ASP.NET MVC with a power of ajax.
are anyone show me the best way i can use to do this in MVC
Here's how you could proceed: the elements of each step of the wizard could go into a separate div. The Next and Previous buttons will show/hide the corresponding div. On the last step there will be a submit button which would send the entire form to the server.
You might also take a look at the jquery form wizard plugin.
One of the ways that I have implemented a wizard is to have a separate database table that contains all of the information you are required to store and to save/retrieve data to that table in each step of your wizard - obviously depending on the size and purpose of the wizard this may not be sensible with the number of database calls but I was implementing only a 5 page wizard with maximum 5-10 fields on each page. So when you land on a page you query the database and retrieve the information from the database or if it doesn't exist load a blank page where the user can then enter the information and it is saved when they click either Next or Previous.
For navigating between pages I simply built a helper class that accepted the page name and button type (Next/Previous) and had a simple switch statement which would return the page to navigate to and then used that in a RedirectToAction statement. Again this may not suit a larger application but you could also look at using Windows Workflow (touched on in this article http://www.devx.com/dotnet/Article/29992) as I know that it can be used to create wizard style applications.
It is not particularly an MVC solution but I advise a client-side implementation using JQuery LightBox.
You don't need any client side stuff to achieve this, it's also bad practise to use javascript for anything other than user convenience.
You have 2 problems with a wisard:
1: maintaining state. ie saving data between requests.
2: figuring out which action (usually next or previous) to take.
Maintaining state.
You can use the session object but ideally (and so you can unit test them) all actions should be pure functions. I use hidden inputs to save data between requests.
User actions.
For a next / previous view. Add 2 submit buttons to your form and give them names. When you
POST the form, the button with the none null value was the button pressed. Then redirect to the appropriate action.
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
I have a page which the user gets shown when he wants to create a new or edit an existing document. There are two UserControls on the page. One simple DatePicker and a more complex grid. After filling out or editing the data he then can press continue which brings him to the review page where he can decide to really create or update the document or go back and change something. Going back is done in javascript with a history.back()
Now when the user is in "new" mode and decides to go back from the review page the grid partially looses its viewstate and the DatePicker loses it completly.
On the other hand when the user is in "edit" mode and goes back from the review page both controls maintain their viewstate.
I know that the browser just shows the cached version of the "new/edit" page. But why the difference in the state of the controls and what can I do so that it works in both cases?
Viewstate is essentially a hidden field in the form that gets populated with the control values that have been posted back to the server.
If a user enters or selects some values in the form's controls, performs a postback and then presses the browser's back button or does a javascript history.back(), you are viewing the page as it was before the postback took place. Therefore, the choices made by the user prior to the postback will not be present on the page.
The difference between "new" and "edit" is that on "edit" you are retrieving information from the database to populate the controls.
Instead of doing javascript history.back(), you should look into using a Wizard control. The wizard control is designed for this very purpose. If the user enters information in multiple steps, goes to the review page and needs to go back a step or all the way back to the first step everything is maintained in Viewstate.