Custom phone numbers control - c#

I have a database that stores an arbitrary number of phone numbers. There are a few pages that (should) allow admins to change these numbers and add them.
I plan to create a custom control that will:
Show all existing numbers
Provide an edit button
In Edit mode, will show an add button
Have an add button that adds the requisite fields in a way that does not cause a postback.
Provide a save button (of course)
These seems like a complicated task. I've done a bit of research, but haven't found any ready-made solutions. Is there anything I should have spotted or should know before I go about writing this from scratch?

I've built something like this using jQuery. Use a table to display the phone numbers. Then, jQuery excels at being able to hook into button presses and manipulate elements on the page (wrap a table cell's contents with an input box, or add add a table row) without causing a postback, completely aside from any server-side ASP.NET controls. Then, on Save you can stuff the phone numbers into an <input type="hidden runat="server"> in a delimited format (e.g., "212-555-1212|617-555-1212") and let the Save button do a regular postback.
You could probably find a commercial datagrid control with Ajax features to enable editing and add rows but you'd probably spend as much time customizing it as you would writing it from scratch with jQuery. It's the sort of thing you've seen dozens of places but everyone does it a little different.

I've never seen a custom control that worked specifically like that. I'd search on CodeProject to see if a custom control exists before writing one.

Are the existing numbers in a variety of formats? For example: 123-456-7890 and (123) 456 7890? If so, you may have to decide in advance on the format you are going to use and then run a script to clean up the existing records. I would use JQuery as suggested by Marc to enhance the editing experience. Validation will have to be precise.

Related

C# saving and loading all form elements?

I'm trying to design my C# winform application with a very generalized function to automatically go through all of the form elements and save their states/values in a text file so that I can load it later. I want it to be very generalized so that it'll be a cinch to reuse this code in future projects, as it wouldn't be heavily tied down to the specifics.
The form elements I want to save are text boxes, combo boxes, data grid views, list boxes and that's about it. I want to save their values and everything about them.
One way that I was going about it was to go through every possible form element and then detect eachs type, and then create the corresponding c# code to re-create its value ('tboxmine.value="blue elephant"'), and then writing the code to a file, so that I could load the code from the file and execute it using the CSCcompiler. My code so far doesn't seem to be working correctly and I'm having my doubts that this compiler is actually running the code inside my application (I think it's possibly creating a new thread?), and it just seems like there's probably a far more straightforward relatively standard way of doing this.
This seems a bit like the reverse "best practice" approach. If you dont't know about databinding I suggest you look into that.
Basically you create classes to represent your data and use databinding to associate controls with your objects. The controls will automatically show the right value and allow the user to change it. If the user has changed the value, your object gets automatically updated.
To save the data, you would use some kind of serialization to store your objects in a file. When loading, you let the Serializer rebuilt your class structure and (best case) you are good to go.
This is not exactly what you asked for, but I think it is something you could use well ;-)
N.B.: Not the complete state of the control is saved. e.g. in a Textbox your text would be saved but the BackColor won't.
To get you started look into this tutorial: http://www.codeproject.com/Articles/24656/A-Detailed-Data-Binding-Tutorial

Is there a ready-made data table view library with paging/filtering/sorting?

I'm building a system in MVC that has a lot of heterogeneous data to be displayed: Customers, logs, etc.
I'm finding that I'm building the same view over and over again in different forms:
Header row (with sorting links)
Filter row (drop-downs, date pickers, etc.)
Data
Paging row
Naturally the abstractor in me is shouting "Build a generic data view factory!", as well it should. However, before I disappear up my own abstracting bottom, has this work already been done elsewhere?
The only option I can currently find is MVCContrib.Grid, which doesn't seem to handle the rendering of filters (although it has allowances for extending the renderer). Is this the only option?
As one may expect a question similar to your has already been done...years ago. So here: grid controls for ASP.NET MVC? you can find a list available data grids, that has been updated in the years. I recommend that you, once and for all, give a look to all of them, so in the furure you may choose the more adequate to your needs. There is no better grid, but each of them has advantages and disadvantages.
Yes, I could recommend this jQuery plugin
http://datatables.net/
My Choice would be between
datatables.net (Already mentioned)
jqGrid (http://www.trirand.net/demoaspnetmvc.aspx)
I've foud the datatables easier to use at first, but finally I've used jqGrid as I've foud it more powerfull.
I've used both KendoUI and jqGrid successfully. jqGrid is a light-weight and less expensive solution if all you are looking for is a grid. One of the things I liked about jqGrid aside from its easy integration with knockout was it's ability to edit data in table cells as well as creating a "edit view" in which the data is edited in a form-type view with labels beside edit widgets.
That said, it sounds like you might be looking for more than a grid, and if so you should also look at using Html helpers to generate the constituant parts (header w/filter, data rows, paging, etc). This would give you ultimate flexibility over where the different parts are rendered on the page. Maybe you want to put the paging controls twice on the page at the top and bottom; maybe you want to put the filtering into a modal dialog box. The ability to simply go:
#Html.FilterControlsFor(Model.PhoneBookUsers)
someplace (or someplaces) on a page and have the helper deal with all of the details is pretty powerful juju.
Flexigrid - nice table plugin, but it is only ui table you should provide appropriative server side processing for selection and filtering data.
KendoUI any day. Theres a ASP.NET wrapper but it's quite expensive. But the jQuery lib is definitly the best out there.

ASP.NET Datepicker without calendar visualization

I'm working in C# / ASP.NET 3.5 and want to enable users to enter their date-of-birth. I've tried the asp:Calendar web control for this, and also considered using the jQuery-UI datepicker, and reviewed suggestions from this question.
All those options don't seem to have the "mode" I want though. I do not want an actual calendar to pop up, but just a Day/Month/Year dropdown. My requirements:
Just three dropdowns, for day/month/year
Ability to set a min and max year
Client side solution for helping pick a valid date (so don't allow 30 + February)
Nice to have: culture based position switch for day/month and month/day
Can anyone suggest such a control? Or should I just move on and build it myself?
Jeroen, there is no built in control.
The simple way to do this is add 3 drop down lists and add all months / years (Those are the simple ones). Days change, so either you can statically add 31 and do some checking, or use a database that holds a bunch of dates and use that as the datasource.
I used a jQuery add in that handled this for me, I was able to update a hidden field that could be read from ASP.Net code behind, sorry I can't remember the exact plug-in but if you search on the jQuery site you should find it (I had a quick look but couldn't track it down, jQuery site search is pants).
jQuery's datepicker might be what you want:
http://www.kelvinluck.com/assets/jquery/datePicker/v2/demo/

jQuery Core/Data or Custom Attributes(Data-Driven)

A similar question was asked here in storing information in a given html element.
I'm still green to jQuery, but I'm looking for the best way to store information on the page. I have a Repeater that holds one image per item. These images are clickable and can fire a given jQuery event. The issue I'm having is, the objects that the Repeater is bound to holds some specific information(such as "Subtext", "LargerImage", etc) which I would like to be accessible from the page.
Core/Data in jQuery accomplishes this just fine, however we would still need to build the jQuery statement from C#, as all the data is stored on the server. To clarify a bit, this is storing information on the page from a database, which is a bit different than arbitrary information being made available through jQuery.
I'm not restricting this question to "how to bind a custom attribute to an element", because I did come across an idea of generating a JS Struct from the C# codebehind to store information, but I'm avoiding any code generating code scenarios(or trying to).
Custom Attributes from HTML5(ie, "data-subtext") are also a possibility as I can easily add those from the itemdatabound event:
sampleImageElement.Attributes.Add("data-subtext", "And this what the image is about");
I'm a bit confused on browser support for this specific attribute though, or if it is even best practice so early in the game. If custom attributes are the way to go, that's an easy change to make happen. If jQuery can accomplish the same, I'd love to be pointed that way at least for my own understanding.
Any thoughts are greatly appreciated.
I'm answering this question only for the record keeping purposes of stackoverflow, as this is the solution I've moved forward with for this scenario. An AJAX call is completely warranted for any larger datasets and is a direction I would definitely go otherwise.
I went ahead with the "data-" field in the HTML5 spec, provided by the jQuery meta-data plugin.
I'm wrote a short extension method on the Web.UI.AttributeCollection class called "AddMetaData", which accepts an IList as well as a string "Key" to ease the attachment to a given page element.
I'm not marking this as the answer just yet, as there might be some community feedback on my own direction.
To clarify what happens in ASP.NET, once the page is served to the client, the objects that the Repeater is bound to on the server are destroyed and are then recreated upon each page postback.
It sounds like you want to achieve some kind of tooltip effect where the contents are retrieved from the server through AJAX? There are numerous different tooltip options available
jQuery Tooltip plugin
Random.Next()'s jQuery AJAX tooltip
dhtml goodies AJAX tooltip
clueTip
that can be used to do this. You could then set up a webservice or page method to retrieve the relevant data from your datasource.
Of course, you could have the content rendered in the HTML sent to the client when the request is processed and simply hide this markup. Then write your own plugin to display the markup in the form you require.

Calendar Questions - Icalendar library, making a actual calendar

I have some questions regarding calendars
Is there any good calendar generates for either asp.net mvc or jquery. I would like to find something that can make calendars and have features like this.
Generates all the months (but of course only features the current month that is being displayed)
If the name of the calendar event is too long it cuts it off and if you click on it a popup comes showing you the full description
Ability to add a new task to the calendar. So when you click on it pops up a dialog box and you can fill out information.
So basically what Google calendar can do. You can add a task then it pops up with like where, time notifications area.
So is there any sort of solution like this for .net MVC or jquery? If not then I am willing to use other javascript frameworks if needed but rather not.
I checked out http://arshaw.com/fullcalendar/ and it really does not have everything I need.
I like this one http://www.redredred.com.au/projects/jquery-week-calendar/
Since it almost does what I want but the major draw back this is that it only does weeks not a full month.
Is there some sort of library that I can use to easily import google calendar data in, outlook calendar data in and basically any major calendar program.
I know that icalendar is like the standard format so is there a C# library that will like parse this stuff?
I going to need to store the calendar data in a database. How would the database table look like?
I think that for the client side, you are asking for a little too much, to be honest. Your best bet is find the one that does the most that you want out-of-the-box but has enough customization to allow for you to fill in the functionality you are looking for. Either that, or write the code from scratch. To be honest, you are rendering a table with some jQuery on the front end for client-side events. It's tedious, but shouldn't be overly difficult.
As for a .NET library to handle calendar formats, I recommend DDay's iCal. It has some issues and requires some understanding to get running, but it works (I use it myself for a site that I project iCalendar entries from).
As for the calendar in the database, that's really up to you. The minimal amount of information you need is a date field, obviously. I'd recommend something with an offset (SQL Server 2008 has the datetimeoffset) since you might want to take into account time zones. Beyond that, any information you want to store is up to you.
In response to chobo2's comment about how to get the data to appear in the appropriate column, when you render the table, you are going to have a 7 x 5 table (seven days, five rows). I would suggest tagging each of them with the date.
Then, as you render your table, when you render the cell, you look to see if you have any events for your date, if you do, then render the cell appropriately.
Why don't you start slightly less ambitiously? Google has a large team working on their calendar and for you to hope to replicate that without taking years will just end up with an unfinished project.
1
You said you didn't like FullCalendar but it does support 95% of the features you need from the calendar, minus actually clicking on days to add events.
FullCalendar is great for displaying
events, but it isn't a complete
solution for event content-management.
Beyond dragging an event to a
different time/day, you cannot change
an event's name or other associated
data. It is up to you to add this
functionality through FullCalendar's
event hooks
You get a dayClick event which you could use to add an event. I wouldn't bother though going this route though, and simply have a separate panel on the page with a text box for the name, a small icon which makes a Jquery UI calendar appear. It sounds low-tech but the pain of getting the click event working in all browsers would be a big task.
This textbox displays the full event name when you click on day which gets around your long text cropping issue. Alternatively this shows you a nice static html iCal-like solution which you may have looked at already.
Generating a month calendar for the year could be done statically using HTML instead of using jQuery.
2
If you stick to the iCalendar format for Outlook and Google, which both support it, then it's very easy to write a parser for that format as it's such a simple text format. This question has more details on making one, you could use an existing library for it.
3
A simple table of equivalent SQL types like below will be enough:
Events
Id
Name
Location
DateTime Start
DateTime End
bool IsRecurring
Recurring events will be the hardest part because of the calculations you have to perform to work out the next event. You don't store each occurrence in the database. Using the epoch for the calculations might help out, it's a technique Exchange uses.

Categories

Resources