Posts Tagged ‘ASP.net’

Entity Framework Seed Data for States & Counties

Written by rsolberg. Posted in All, Software Development, Technology

One of the great benefits of Entity Framework and Code First for ASP.NET MVC application development is the ability to seed data for your application when you run your application for the first time. Earlier today I was working on an implementation of EF and Code First for a new app and I had all kinds of fun in Excel concatenating() my c# code to seed States and Counties in my app. Rather than force everyone else out there to experience the same joy I did, I through the code into a quick app and posted it on GitHub for you all.

How to select the first element of a dropdown using jQuery?

Written by rsolberg. Posted in All, Software Development

Let’s suppose that you are trying to identify what the first element or value us within a dropdown menu or specifically a select list. Suppose that your select list looks like this… If you wanted to figure out what the very first element of the drop down was, you could use this line of jQuery to get it. Suppose that you wanted to update all the selects or dropdown menus on your page to the first item in the list… You could do that by executing this line of jQuery.    

Convert ASP.NET Website to ASP.NET Web Application

Written by rsolberg. Posted in Software Development, Technology

HatM /Free Photos
It wasn’t that many years ago that it seemed like I’d create a new ASP.NET website a few times a week.  Some for rapid prototyping and others for release.  At the time, the applications felt really easy to manage.  That is until they grew and became a beast with all kinds of integration needs. As soon as you start needing to integrate with other systems, databases, applications, etc. the ability to use namespaces and existing components becomes a requirement.  Without it, your code would become completley unmanageable with a complete lack of reuse of components and functions.  I’m not saying that you can’t maintain some good coding practices within an ASP.NET website, but when the app grows and its being integrated with, I absolutely hate code sprawl.   My philosphy on coding is rather simple:  Code it once so that you can reuse it at least twice. Obviously not every code block you write will be reused, but say you have a function to get a contact’s name from your CRM system…  It would seem like this is something you’ll do over and over and over again, so code it once, use it at least twice… With all that said, the need arose to be able to convert these growing ASP.NET websites into ASP.NET Web Applications.  When I got to that point, I was able to find a great resource by Mohamed Meligy on this very topic. Essentially it comes down to a few steps…
  1. Create a new blank solution within Visual Studio
  2. Add a new Web Application Project to the newly created solution
  3. Import existing website files into newly created Web Application project (overwrite files as needed)
  4. Manually add references into the new project that you had in your old website
  5. Once all refernces are added, you likely have many namespace errors.  Create the new namespaces as required.
  6. Now we need to perform a conversion process on the web application project, right click on the new Web Application Project and select “Convert To Web Application”.  This should fix missinging designer.cs or designer.vb.
The above steps will still keep all of your code within a single project in Visual Studio.  Depending on what the application is, does, etc. you may be better off adding a few different projects to seperate database connectivity, data models, and classes that interact with the DB.

SQL Azure & Updated Pricing

Written by rsolberg. Posted in All, Reviews, Technology

One of the biggest challenges I face daily is how to build and architect cost effective technical solutions to improve our business processes. While we have no shortage of ideas for processes we can enhance, we are very constrained on capital to invest. With all that said, we still have to operate and improve our processes. Our goal as a business is to be the best at what we do which means we also need to make sure we have appropriate scalable technical solutions in please to meet the demands of our users. Over the past few years our Customer Relationship Management (CRM) database has become our Enterprise Resource Planning (ERP) system. This system tells our staff everything they need to know about our customers, potential customers, and what activities need to be completed and when. This system is an ASP.NET web application with a SQL database on the back end. In the days leading up to our busy season, we had an Internet outage (thanks to some meth tweakers for digging up some copper!) and only one of our offices had access to our system. At this time, I knew that our business required us to rethink the hosting of our server and services. After working with various technical partners, we determined we could collocate our existing server in a data center for a mere $400 per month. While this was a workable solution, the only perk this would really provide us was redundant power and internet access which we didn’t have in our primary location. We still had huge redundancy issues with our server in general, and by huge I mean non-existent. In other words, if a hard disk failed, we were SOL until Dell was able to get us a replacement. Since our busy season of work had just begun, I decided that we’d roll the dice and address the concerns in the 1Q of 2012.

Enter Azure

When Azure was announced from Microsoft, I initially brushed off the platform. I found the Azure pricing model way too difficult to comprehend and I really wasn’t willing to spend the hours, weeks, or months trying to put it all together. Things have changed though! On February 14th, 2012 Microsoft announced that it was reducing the pricing of SQL Azure and I decided to see if I could figure out what that meant. While digging into this, I came across a nice article written by Steven Martin that did a good job explaining the costs.  After reading the article, I decided to evaluate the pricing calculator again.  Winner Winner Chicken Dinner! I could move our entire database to the SQL Azure platform for $9.99 per month!  This would at least handle some of the disaster recovery and scalability concerns.  The only other piece to the puzzle would be our ASP.NET web application.  While I have scalability concerns with that, disaster recovery isn’t really a concern because the data drives the app.  In other words, a Windows PC can running IIS would work until the server is fixed.  But what if the cost wasn’t an issue on the Azure platform?  Would it be worth it?  Five months ago, I couldn’t have told you the cost.  With the updated pricing calculator, I can see that running 2 extra-small instances of our ASP.NET web app will cost $60.00 per month.  VERY AFFORDABLE! While I’ve not deployed our solutions to Azure yet, it is something that I’ve got on the list to complete within the next 60 days.  Hosting our entire application for less than $70 per month (ok, a penny less… but still!) is amazing!  I’ll write another blog entry once we’ve tested the Azure system out, but very promising!!!!!

What if your database was 30GB?

ELMAH For Multiple Environments

Written by rsolberg. Posted in All, Technology

Web applications today, especially in medium to larger sized enterprises will be deployed in multiple environments. This allows the development teams to deploy the web application to an environment to verify changes made and that the application functions as expected before shipping it to production. So when you go to use plugins out there such as ELMAH, how should you go about this?  Out of the box, ELMAH allows you to set a single connection string name within your web.config as shown below. So what do you do when you actually have 3 different connection strings for all the environments that your web application exists in?  As it turns out, this is pretty easy to do because ELMAH is open source.  When you download the ELMAH code, you can include it inside your Visual Studio Solution or create a new solution specifically for ELMAH that you can reference from your web application.
If you’re reading this I’m guessing you don’t need help on how to go about doing that.  If you have specific questions, use the contact me page or the comments below.
With the ELMAH code open, look for the SqlErrorLog.cs file and add the code below.  This essentially allows you to set  the connection string property via your application to handle variations… So suppose this was a real world situation where you have a few different connection strings to manage like this: From your Global.asax.cs you can add a line of code to use the correct ELMAH database…
If you’re looking for more information on this, please contact me and I’d be glad to help.

ASP.Net GridView Context Menu

Written by rsolberg. Posted in All, Technology

This post will cover how to add a context menu to a GridView in ASP.Net utilizing jQuery. Once your site is setup to utilize jQuery, you can simply include a new style sheet and script file and get awesome functionality fairly easy! Take a look at this site here to download the required files and their code samples. Mine below shows how I used this on a GridView in ASP.NET…

GridView

Menu

jQuery Initialization

ASP.Net MVC MarkItUp Rich Text Editor

Written by rsolberg. Posted in All, Technology

MarkItUp identifies itself as being the Universal Markup Editor and from as far as I can tell, this is probably true! It was very easy to integrate the jQuery editor into my new Blog Admin views. I will try to illustrate how I was able to do this below. In addition to the jQuery MarkItUp files, you will also need to download the MarkUp to HTML parser/enhancer of your choice. I used the MarkdownSharp framework which is what the makes of StackOverflow.com have recently converted to an Open Source project.

Download the MarkItUp Files and MarkDown Sharp

You’ll need to take a look at the MarkItUp Website and download a couple of different files. – markItUp! pack 1.1.6 – Basic MarkDown Set – MarkDownSharp

Include MarkItUp Folder In Your Project

Now that you have the files downloaded, you need to deploy them to your MVC site. I have deployed the MarkItUp folder to my Scripts directory. The MarkItUp folder contains 3 different folders (sets, skins, and templates) and you’ll find a couple of .js files in the root of the folder. Once the MarkItUp folder is in your project, open up the MarkDown file that you downloaded above. You will need to deploy this folder into the Sets folder described above in your project.
© Copyright RSolberg, 2003 - 2014. All Rights Reserved