Sunday, June 30, 2013

MVC4 with jquery-ui datepicker

Here's the steps, and they're very simple.  You only have to do it this way if you want to use the built-in bundling and minification, if not you can always use the exact same code you would use in an HTML page, but you would have to comment out the bundle generation code.


  • Create a new MVC4 project and Select the Internet template. Use all default options.
  • Edit the _Layout.cshtml in ~/Views/Shared and add these two lines after the jquery bundle at the bottom
  • @Scripts.Render("~/bundles/jqueryui")
  • @Styles.Render("~/Content/themes/base/css", "~/Content/css") -- NOTE Styles.Render, not Scripts.Render as in your code
  • Either edit the Index.cshtml and delete everything, or create a new Controller action and blank view.
  • Inside the view, add the following code, Press F5 and you're done!




Friday, June 21, 2013

Visual Studio 2010 Startup Gets Faster, Just disable TFS autoconnect feature and Save a lot of time

If you have experienced that opening Visual Studio 2010 takes too much time as it tries to connect to TFS automatically, you can now disable TFS auto connect and once visual studio is up then connect it to TFS which take very less time.

For achieving this You can install the TFS power tools, you can download it here


  1. Please close all the Visual Studio and TFS instances before you start installation.
  2. After installation open up a visual studio command prompt and run the command “tfpt connections” this will bring up a dialogue which will show all of your available TFS servers and Collections.
  3. There are 2 options you can try, firstly uncheck "Automatically connect to server on startup" this should stop VS trying to connect to TFS when you open a solution.
  4. If that doesn't work then click on the "+" next to the TFS server and select the collection you are using for source control. Hit the "Edit" button and you should see a checkbox called "Server is Offline" select this and you will no longer be connected to TFS.
  5. To reverse the behaviour use the same tool to togle the values back to their defaults.


Sunday, June 16, 2013

How to Allow Visual studio to let you edit the code while debugging? Allow Editing the code while debugging.


Many times we come across a situation when we are debugging the code in Microsoft Visual Studio and we find something is missing in our code and we need to change it.
If our setting is not proper we need to stop debugging and then change the code and re run, which takes a lot of effort and time.
To avoid this we can simply do the following :

If you want to make any changes while debugging then you can edit and continue the application, if that option is enabled. to check this option is enabled or not, go to Tools->Options then 



There you go :)

Friday, April 19, 2013

Run Visual Studio 2012 as administrator every time


As a developer I spend my life inside Visual Studio. Since I installed Windows 8, I was having trouble opening web projects. Turns out that I need to run Visual Studio as an administrator.

Rather than right clicking the shortcut every time and another click to run as administrator, I found a permanent solution. For the lazy me, it saves two extra clicks.

Open properties of the shortcut to Visual Studio 2012, go to Shortcut tab.


Click on Advanced and then check Run as administrator checkbox.


Yipppie !!!


Thursday, March 28, 2013

Adding custom fields to a VS2012 MVC4 SimpleMembership system

Adding custom fields to a VS2012 MVC4 SimpleMembership system
Add custom columns/fields to your MVC4 SimpleMembership "UserProfile" table
MVC 4 in Visual Studio 2012 introduces the new SimpleMembership Provider as its default web-based authentication system. While this system is much simpler than the earlier ASPNETDB system that it replaces, there definitely are a few new and neat tricks to be learnt.

One of them is: How do I add custom fields to my MVC 4 registration system?

It can be done in just 4 simple steps:

1. Start up VS 2012, and create a new MVC 4 web project. Set up your SimpleMembership registration system - for some help, please see post on setting up a SimpleMembership Provider in a VS2012 MVC4 project.

2. Next, run the project and navigate to the login page, so that the tables get created. It is not necessary to create a user at this point.

3. Then, in your database, alter the table UserProfile, and add a column: FullName (nvarchar(50)).

4. Next, add/reference the new FullName field in the following programs in your project:
In class UserProfile, in AccountModels.cs (to ensure the class matches the table columns):

    [Table("UserProfile")]
    public class UserProfile
    {
        [Key]
        [DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)]
        public int UserId { get; set; }
        public string UserName { get; set; }
        // Customization: Field(s) added
        public string FullName { get; set; }
    }

In class RegisterModel, in AccountModels.cs (to enable handling on the registration form):

    public class RegisterModel
    {
        // Existing code
        // ...

        // Customization: Field(s) added
        [Required]
        [Display(Name = "Your full name")]
        [DataType(DataType.Text)]
        public string FullName { get; set; }
    }

In the Register.cshtml view (so it'll appear on the user registration form), add a new li element with the following content:
    @Html.LabelFor(m => m.FullName)
    @Html.TextBoxFor(m => m.FullName)

In the [HttpPost] Register ActionResult, in AccountController.cs, modify the call to the CreateUserAndAccount method (to write the new column to your database):
    // Customization: Field(s) added when creating a new account
    WebSecurity.CreateUserAndAccount(
        model.UserName,
        model.Password,
        new { FullName = model.FullName }
        );

Now run your program and register a new user, supplying a value for the FullName field... success! The new row created in your database table contains the value supplied for the new column!

Note: This post covers how to create a custom column. A near-future post will explain how to access the value of that column from within your VS 2012 MVC 4 projects. Please re-visit my blog occasionally :)

Happy coding!

Tuesday, March 26, 2013

Solution to Sys.WebForms.PageRequestManagerParserErrorException

If all of the above doesn't Work I have a full proof Working solution :)
Add this Attribute to your script Manager EnablePartialRendering="true"

  Like below:  
  <ajaxToolkit:ToolkitScriptManager ID="_scriptManager" runat="server" ScriptMode="Release" CompositeScript-ScriptMode="Release" AllowCustomErrorsRedirect="False"  
     EnablePartialRendering="true" >  
   </ajaxToolkit:ToolkitScriptManager>  
 And in code behind write this code   
  Protected Sub _scriptManager_HandleErrors(ByVal sender As Object, ByVal e As AsyncPostBackErrorEventArgs) Handles _scriptManager.AsyncPostBackError  
     If e IsNot Nothing AndAlso e.Exception IsNot Nothing Then  
       Logger.Current.LogError(e.Exception.Message, e.Exception)  
       'Changed to catch the Error in Master Page Ajax Error Control Sys.webforms  
       _scriptManager.AsyncPostBackErrorMessage = e.Exception.Message  
     End If  
   End Sub  

Monday, March 11, 2013

Deploying your site with SQL CE 4.0 to shared webhosting

If you have a VPS or dedicated server, you got full access to it and normally shouldn’t run into any problems. But when you’re using shared webhosting, your actions are very limited. This post describes the errors you’ll most likely run into the first time you try this, and how to solve them.
You can either deploy from within Visual Studio or FTP the files to your host. If you hit the URL to your website, you’ll most likely get following configuration error with the according web.config fragment below:
Parser Error Message: Could not load file or assembly 'System.Data.SqlServerCe, Version=4.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91' or one of its dependencies. The system cannot find the file specified.
You get this error because most providers don’t have SQL CE 4.0 assemblies installed (yet?). This means you’ll have to 'bin deploy' the assemblies together with your site. Visual Studio 2010 provides a "Add Deployable Dependencies..." context menu item, which let you choose to add the required assemblies for Razor or SQL Server Compact to the Bin folder.


With some 'luck' you hit the next error once you solved the problem above and refreshed the page:
Parser Error Message: Access to the database file is not allowed. [ 1884,File name = somepath\App_Data\YourDatabase.sdf,SeCreateFile ]
For this error you have to give read + write access to the App_Data folder, usually done in the File Manager of your hosting control panel. If you got this error on your private server, check if the service running the Application Pool (e.g. Network Service) has these rights on the folder. You will also have to add following line of code (e.g. in the global.asax file):
AppDomain.CurrentDomain.SetData("SQLServerCompactEditionUnderWebHosting", true);
This is because, by default, SQL CE blocks access when the connection is opened under the ASP.NET networking process. Once I ran through these steps, I got everything up and running without any hiccups.

Source: http://www.bartlannoeye.be/blog/deploying-your-site-with-sql-ce-4.0-to-shared-webhosting-part-2