MVC auto complete inputs according to recent user entries - c#

I have a site that manages a database.
Lets say the users enter information about people (height, weight, name etc...)
A lot of people are entered each day and the height range is quite small so if a user entered a person with a certain height I want it to auto complete next time he enters a person.
(like most login forms where you click a textbox and it shows your recent entered login info and when you start typing it auto completes you).
I am using MVC 4 and the person entry is not within a form. When a user clicks save it uses ajax to save.
I know it works with forms but how can I do it on certain textboxes which arent in a form.

The jQuery autocomplete solution doesn't require fields to be in a form.
If you look at the source code of the sample, the previous data is stored as a JavaScript array. You could store previous entries for each user in a database and then use this data to build an JSON array that can be passed via a view-model to the view and then use jQuery.parseJSON() to render it straight into place in the JavaScript.

Related

How do I save the data on a user control before switching to a different one?

I have a WPF Application with different user controls. Each of them can be accessed by clicking a button on the left side. My issue is, when I am in one of the user controls and filling out the data in textboxes, combo boxes etc, I may have to stop it mid way and click on another user control. While doing that, I need to keep the data in the previous user control intact so that when I return to the first user control, the data should be present in all the controls before I left it. How do I achieve this? Here's a sample picture of how my application looks like:
Picture Credit: https://rachel53461.wordpress.com/2011/12/18/navigation-with-mvvm-2/
From the picture, if I am in the Products Page, I might have several text boxes with data entered in there. For a variety of reasons, I may have to step away from this and click on Home Page or some other page , do some work there and return back to the Products page. When I return, I need the data to be present as is when I left it.
Thanks in Advance
You must have create a ViewModel to each diferent user control.
ViewModel remains in memory until you process that or make a diferent process.
For Example you hava a User control for your Main Page, that's mean you have a view (MainPageView) of your user control for your main page, that view belong to a ViewModelMainPage.
For Products you maybe have a ProductView, that's belong to ViewModelProducts.
You must create a ManagerViewModel to manage the view for diferents user control.

Display and preserve model

I have a two stage process:
A user completes an application form which is stored in a db and an internal team validates the data at which stage the user is send an email link asking them to complete the application.
A page is displayed to the user containing all of the information that they originally supplied with a confirmation button.
My problem is on step 2, I'm populating a model on page load and displaying this information to the user but when the user submits the form the model being posted back is empty.
If I use #Html.TextBoxFor(m => m.name) etc. then the model will still contain the value of the property but I all I need to do is display the values to them rather than give them the opportunity to amend them (they're actually not allowed to amend them at this stage).
Is there any helper that I can use for this or is there no way around this?
Thanks,
C

How can I stop a user that tries to enter a name instead of selecting from a list in AutoCompleteExtender? ASP.NET

Here's my situation: I'm programming using C# in ASP.NET and I use SQL Server for a database.
On this particular page, the code behind is done in VB (long story, the usual code behind is a .CS file but this is one of my earlier pages). I have users that enter the first few letters of a last name and then AutoCompleteExtender shows the rest of the names in the database with those starting letters. Not only that, it shows name and the person's unique ID number (this was done for a specific reason). The name and ID are separated using the delimiter "|" (i.e. Babbatt, Aaron | 9920).
IF the user doesn't click on one of the names (like they should), and just enter a name .. I need to create something in the code behind (in VB) that yells at the user because there's no unique ID number attached to the name. Basically, I don't want them to enter a name without selecting one on the list given in the database. As it currently is, if a user types in a random name and hits submit, it goes through to my database which I don't want. can I do this without utilizing the code behind in VB?
What's the best approach here? I'd prefer not to use a straight up SCROLL BAR because this page was designed for users to be able to enter data quickly and selecting from a massive list of names doesn't fit that criteria.
I'm stuck. Thanks for your help.
Rather than default to yelling at the user, you can check the name against your list and try to find a match. If it exists, use the matching ID, otherwise, report back that the user was not found.
This would be done as part of validation.
You can also see other suggestions here: Using the AutoComplete feature of ComboBox, while limiting values to those in the list?

How to write a C#/ASP.NET MVC 3(razor) based, simple, photo gallery?

I can do this in Javascript by pulling a series of thumbnails as an array. Then I know when I'm on the first photo, or the last, and can show controls based on that.
How can this efficiently be done on the server side using C#/ASP.NET MVC 3(razor)? For example, on my site here, is one photo, out of 19 photos. I'd like to add next/prev functionality.
Do I have to pull the entire array of photos, parse out the current photo, determine if it's first or last, then build next/prev buttons?
When there is a photo gallery, there is One photo from many photos, and when there is a concept like x items from y items in which x < y, then we all think of paging. Photo gallery is almost like a grid with one item and two buttons for going to the next page and previous page. If you want to implement paging by yourself, there is no need to fetch all photos and compare them to the current photo to create next/previous buttons. All you have to do, is to cache current item index and the count of all photos, and on each rendering, calculate to see if you need to render next, previous, or next and previous buttons.
Making one complete page load per image is inefficient, slow and will send your visitors away of your site quickly.
I have recently creating a decently fast ASP.NET MVC photo gallery using the following techniques:
When the visitor clicks on a certain folder an ajax request is sent to the server requesting the folder's thumbnail collection (the data is returned in JSON format)
The thumbnails and other UI components are rendered using a model view view-model framework called Knockout.js (btw, it is great!). The information retrieved from the server is passed directly to the knockout binding model in JSON format, so you don't have to do any serialization or marshalling.
When the user clicks on a certain thumbnail, an ajax call is issued to the server, to retrieve a JSON object containing the image information: a) the main image URL c) next and prev images (if any) d) exif information c) comments for that image, etc.
Knockout.js knows how to render the prev and next arrows (if any), and all the other information to the UI view-model, so they refresh automatically.
If you combine that with some server side caching, you'll have a pretty fast photo gallery application.
Cheers!!
iván
You didn't specify a client technology, Silverlight, ASP.NET MVC, ASP.NET Webforms, WPF, Winforms..
The concept is as follows.
Choose a client /presentation technology
Decide where the photos are going to come from (Database, Webservice (Infront of a database)
Create methods to get next and previous photos for a specific series (Album, User, Globally)
Call these methods on a Forward or Backward (button/image) click.
You can get this going in several ways:
Create an aspx page which gets the first photo and create buttons that call this same aspx page, but with a query string of the next or prev photo, as needed. This solution will cause postbacks, so you need to decide if this works for you or not.
Create an aspx page which gets you a photo based on the query string and call it via jQuery ajax.
Create an ASHX file which returns a different image for a query string parameter and make it the SRC for the image.
These three methods allow you different levels of interactivity vs. postback. If you decide which route you would like to take, we can help you get there :)
I don't know why you go for this in C#. While doing it in C# i will use ajax call. For this i will load only the first image and Total image count initially.
According to the total count and current image no show the prev and next button.
On clicking the next and prev button take the corresponding image from db using ajax call.
I dont know how to use but there are many jquery plugins to show gallery

Ways to detect changed account/no account found in ASP.NET/C#

I have an ASP.NET page where at the top of the page is a search box. There are 2 text boxes - one is an autocomplete extender for the Name on a database, and one is just inputting the ID.
The page features DetailsViews and GridViews primarily, and even when no account has been searched for, these display blank data which is not ideal. I sort of fixed this by using if (IsPostBack), encasing the elements in a placeholder and setting it to visible only if the page ispostback. But this doesn't cover if the user types in an incorrect ID.
Also, some accounts have huge amounts of data inside the GridView's. I had an issue where because I have no way of detecting when a data source's rows has changed, I end up binding whenever the page loads (Page_Load method). I've come to realise this is simply very bad - there are lots of times when the user can click various things in the page and have the page postback, and it takes an eternity to load each time I click something for accounts with lots of data.
Anyway, my question is essentially two-fold but I have a feeling the solution will be similar:
1: How can I detect when there are no accounts returned when searching, and disable the Grids/Detailsviews and show an error message?
2: How can I figure out when the user searches for another account and only rebind the grids after that has happened?
Thanks
This method is very ugly but it'll get the work done.
1) To Check whether there are no records; after the AutoComplete Extenders Webservice is called if no record is returned put some value in Session like
Session["NoData"]=true;
if Records are found then;
Session["NoData"]=false;
after the webservice is called do ajax request to check that session & on the basis of value do what you want.
2) You can achieve this also by following the above option.

Categories

Resources