I have a webpage in asp.net which uses editable grid to update/insert employee's records. A particular employee can have almost 50-70 attributes. Considering the frequent use of this page, I need to be very careful about the round trips to server and other I/O operations, as it might degrade the performance of page.
I am using a jquery plugin to choose from the given available columns. The left panel of listbox is populated using an xml file, which is read on server. The attributes are of multiple datatypes, such as simple string, integer or date.
The problem comes with the attributes which contain dropdown values, such as department, teams etc. Should I load the values of the dropdown values as the page loads in the start, irrespective of whether the user wishes to select the dropdowns or not? Or should I make another round trip to server and load the dropdown values of the selected attributes. Which approach should be used and why?
Note: There might be atmost 4 to 6 dropdown attributes, with maximum 30 to 40 values..
It really depends on both the odds of the user needing that dropdownlist, and how badly you'll want to avoid additional Ajax loads.
This is a very specific issue. But if your dropdownlist items won't really change on a per-item basis, I'd go with loading them during pageload. Else, if one employee's dropdownlist won't be the same as the other's, use Ajax so you can get a custom dropdownlist every time.
But like I said, very specific for your particular situation.
Related
I have a form in which I am gathering information from the user. Based on the value of one of the dropdowns, I am showing a panel to the user. This panel contains textboxes, dropdowns etc.
Suppose the user fills in all the values, I want to show him an add more button. On clicking this button the value in the panel should be saved somewhere and the panel should go blank for adding more values. This way a user could enter values a number of times before the final submission. On final submission all these values would be saved to a table. Could somebody guide me with the methodology of how this could be achieved??
Also I want to know how this kind of thing can be achieved at the frontend?
You can either make use of Lists for this purpose or simple arrays.
You have not mentioned your fields clearly , but suppose they are, username, address, telephonenumber.
Then you can make list or dynamic arrays for each of these fields and on final submission, you can do Bulk Transfer to the database.
Link For Lists:
http://www.dotnetperls.com/list
Link For Bulk Insert:
http://blogs.msdn.com/b/nikhilsi/archive/2008/06/11/bulk-insert-into-sql-from-c-app.aspx
One way to do it, would be to use KnockoutJS where all adding/removing and UI manipulations are done by the library. Then submit JavaScript object as JSON to the server, serialize into objects and insert/update the database.
I have to create a data entry form in asp.net webforms where the user could enter several member details. Each member detail will have about twenty data items such as FirstName, Lastname, DateOfBirth etc. The number of members entered can be anywhere from one to say twenty.
Once all the members entered or during the entry process, they should be able to go to the previous or next entry and make changes. Essentially there should be a Next and Previous buttons which will traverse the pages. At the end when the Save button is clicked all the entered data should be saved.
I have created a UserControl, which has all the textboxes to enter data. I have created five hardcoded panels which display the usercontrol five times. This makes the total members that could entered as five.
I would like to replace this hardcoded model with a dynamically added panel, when the next button is clicked.
Please let me know how this could be achieved. Or if there is a better architecture please let me know. I tried the wizard control, but it was too cumbersome in maintaining the previously entered values and traversing data using Next and Previous buttons.
Thanks
You could add the controls dynamically to the page using:
Page.Controls.Add(new MyControl());
You'll have to find a temporary store for the data entered in the controls though such as Session.
Session["addedControls"] = myControls;
You can track the number of controls they add and then loop though and save all the data to whatever permanent store you're using.
There's an example of this here: http://howto.jamescarnley.com/2008/05/adding-fields-dynamically-in-aspnet.html
Storing the entire control in session does have it's drawbacks such as the overhead involved, you could just store the data which is more efficient but is a tiny bit more effort to implement.
This will also only work if they have cookies enabled.
Alternatively you could have a drop down list for them to select the number of entries they wish to make and display that number of controls by calling Page.Controls.Add the number of required times. Then just save them all in bulk at the end.
You could dynamically add the controls you need to input a new member easily enough in javascript. What you propose sounds like a nightmare to me. I'd put up a page with the controls to add a member and an 'Add Member' button. When the Add Member button is clicked - I would save the member to the database, retrieve a list of members added in this session - and display the names of the members in a list to the right of the 'Add Member' area of the page. If they want to review a member they can click on their name and you can show that member ready to be edited. Or they can add another member until they have finished. What you are trying to do is going to be a nightmare to manage and won't be any easier for the user to use.
Using dynamic controls will be very difficult and not user friendly as it may require refresh the page or using update panel
in your case, I would recommend doing it all from JavaScript using Knockout, This is a full sample Knockout Grid
Make sure after adding or editing the grid, you will serialize the JavaScript objects into string using JSON.Stringify and add this text to a hidden field.
On form submission, just get the hidden field value, use newtonsoft json library to convert the string into an object and fee free to use the object which will be a list of your model (ex: Order).
Compared to dynamic controllers, this is more manageable and user friendly
I'm creating an e-commerce site in ASP.NET.
For the actual products available to buy, I've placed a box with two arrows, which allow the user to modify the quantity of a specific item. This feature has been implemented in Javascript, so as to avoid postbacks which would be the result of managing this through ASP.NET/C# code.
Now the problem is, how am I to store the items which are ordered? Since the user can modify the quantities and products selected on the fly, I need to figure out how to pass the selected items onto another aspx page (for checkout).
Due to strict requirements, I cannot use a shopping cart. Just literally allow the user to play around with quantities of items, then once the 'Checkout' button is pressed, the user is directed to a payment page where his items are displayed.
Since the selection of items is carried out in javascript, I need to find a way of passing the selected items to another .aspx page.
I thought of storing the items in a javascript data structure, sort of like a table. A product ID will be stored in one field, and the quantity of te respective product will be stored in another field. Once the checkout button is pressed, this data structure is passed on to the .aspx page and handled from there in C# code.
It seems a bit coplicated, especiially since the javascript structure may be modified multiple times if the user changes the selected products and quantities before pressing 'checkout'.
Any ideas?
You can use JSON data in your javascript code and then pass it to ASP page with GET or POST.
At the server side you can parse JSON to .net object using JavaScriptSerializer or DataContractJsonSerializer.
Updated: In JavaScript JSON data should be looked this way:
var orders = [
{
"ProductID" : 123,
"SomeData": "some additional data if needed",
"OrderedCount": 3
},
{
"ProductID" : 321,
"SomeData": "some new additional data if needed",
"OrderedCount": 1
}
];
It is an array of orders.
Sounds like it should be pretty easy. On the page with the quantity boxes and checkboxes, you just run an iterator over them, finding first products to be ordered (assuming the page is not already displaying only products to be ordered) and then within that set finding out the quantities. You can then serialize these or otherwise create a data object and pass these to your ASP page with GET or POST (whatever you prefer).
In other words, sort of like the idea you already had, but I don't see it as being overly complicated to create or manage. Most of your functions can be reusable and repeatable.
As per Jared Farresh's comment, cookies make good sense, too.
From the comments under your question it appears like your apprehension to a "shopping cart" is related to the overhead that would likely go along with a server-side shopping cart.
But, have you considered using a client-side shopping cart? You can still use the shopping cart metaphor to reduce the complexity of the "javascript data structure, sort of like a table", without having a persistent back-end implementation.
simpleCart js is an open source, light-weight implementation of this concept. It works by storing the data in a cookie. You can retrieve it directly by querying the object or you can specify a class on an HTML element and the start up script will automatically replace the inner HTML of that element with the requested value. For example, a <span class="simpleCart_quantity"></span> will immediately have the quantity of items in the cart as its inner HTML after the page loads.
You might also want to check out this post that I asked when I was working on a project with similar requirements: Open Source client-side Shopping Cart - jQuery/Cookies
I have a gridview on my page that gets bound to user search results. There can be many pages upto say 1000. Each page shows 50 records. I have the built in paging turned on for the grid. I want to disable the viewstate on the grid but then I have to bind the results on every page load. (bind twice on paging). The search takes a few seconds and I would not want to store the results in the session. So, how do I achieve turning off the viewstate for the grid or is it okay to have it enabled?
This must be a very common scenario. I hope there is a standard way of doing this.
Depending on how you bind the grid view you should implement server side paging so that your only bringing back the data from the server you need to display for one page.
What data access are you using i.e. are you using linq to sql?
Heres an article on how to do it with ObjectDataSource Custom paging and sorting
Avoid where ever possible putting large amounts of info into view state as it will bloat your page and effect performance.
I have this program in which I am trying to store a collection of values into a list and session
Example:
valueCollection = (List<Values>)Session["Value"];
I want to do the front end in a way which will show a table with each row showing a label and textbox. This would be too simple to do obviously but I want it to show 4 rows of the table by default and then the user can select "add another" this will then add another row onto the table with a label and textbox exactly similar to the 4 default. Everytime the user selects "add another" the table increments by 1.
How do you do something like that, or is there an easy way?
Here is a screenshot to explain it better:
http://img828.imageshack.us/img828/9986/idead.png
The basic idea is that you bind a control to your data and provide GUI controls to allow users to add/edit/delete records. Once the records are modified you re-bind the control to see the changes.
Take a look at the Databound controls in the .Net Framework. For a quick first pass you could use a ListView - a control which provides built-in functionality to automatically generate and mange the add/edit/delete GUI elements.
In 'real world' usage, storing big datasets isn't a great idea as more users = more sessions and each session uses server resources. You should really be getting/storing your data in a database or perhaps an XML file.
HTH