RSS 2.0
# Wednesday, July 28, 2010

Well, this is interesting:

image

Wednesday, July 28, 2010 8:13:27 PM UTC  #    Comments [0] -

# Sunday, July 25, 2010

Is the filter box in the Add Reference dialog.  Hallelujah!  What took sooo long?

image

Technorati Tags:
Sunday, July 25, 2010 12:43:05 PM UTC  #    Comments [0] -
Visual Studio
# Friday, May 21, 2010

Was working on the beginnings of a new project and building up a database just by using a file based database connecting with SQL Express.  When it’s actually deployed, it’ll be on a full SQL Server, so I scripted the database and executed the script on my local SQL Server.  The database already had the membership tables built in.  I also knew that I’d not be connecting to it via sa for obvious reasons, so I created a stripped down SQL account to connect with. Good enough.

So, modify web.config to change the connection string and the each of the provider entries to point to the new connection string.  Simple enough.

Run the application connecting to the server and greeted with this:

The 'System.Web.Security.SqlMembershipProvider' requires a database schema compatible with schema version '1'.  However, the current database schema is not compatible with this version.  You may need to either install a compatible schema with aspnet_regsql.exe (available in the framework installation directory), or upgrade the provider to a newer version.

Things that make you go hmmmm…

headscratch 

So, I quickly Google with Bing and find this. http://forums.asp.net/p/985097/1267872.aspx.  Ok, fair enough, I did just script it rather installing it.  So I ran aspnet_regsql to remove everything then ran it again to add it all.  Ok, the schema table that’s mentioned in that article is populated and anything else that might get missed from scripting should be there as well, right?  Right … well…

Run it again and same error.  Ok, change the connection to use sa and run again.  Works.  Ok, permissions issue.  Originally had the permissions set up for the account that I wanted to use for the application:

image

Scrolling up a bit however, I notice a bunch of permissions just for all the membership stuff. 

image

Ah, all I’m using right now is basic reads from the membership stuff, so just gave the account the above permissions and we are in business!

Hope this helps someone else along the way!

Friday, May 21, 2010 12:52:27 PM UTC  #    Comments [0] -
.NET | SQL Server | Visual Studio
# Sunday, May 09, 2010

Ok, one thing that I miss in Outlook 2010 is the ability to get an email’s properties from the listing.

image

Use to be that I could right-click on any of those and get the properties (full headers is what I’m looking at) so I could analyze them without actually opening the message.  Now I have to open the message to be able to see that information easily.  Am I missing something?

Sunday, May 09, 2010 1:53:17 PM UTC  #    Comments [0] -
Office 2010
# Tuesday, May 04, 2010

In this post, we are going to demonstrate some simple Ajax updates.  We will be using the AdentureWorks db for this.  You can download it here if you don’t have it.

Launch VS2010 and create a new ASP.NET MVC 2 Application:

image

For this, we’ll skip creating the test project.

Next we’ll use LINQ to SQL to generate some data models.  Right click on the Models node and Add Item (or Ctrl-Shift-A when the node is selected):

image

When the designer comes up, add the Product and ProductCategory tables.

image

In HomeController.cs create a new method called ProductSearch:

We’ll need to use our model, so add

using AWAjaxDemo.Models;

then we’ll add our new method:

public ActionResult ProductSearch(string query)
{
    IList<Product> products = new List<Product>();
    AWModelsDataContext db = new AWModelsDataContext();

    if (!string.IsNullOrWhiteSpace(query))
    {
        products = db.Products.Where(p => p.Name.StartsWith(query)).OrderBy(p => p.Name).ToList();
    }
    else
        products = db.Products.OrderBy(p => p.Name).ToList();

    if (Request.IsAjaxRequest())
        return View("ProductSearchResults", products);
    else

        return View(products);
}

 

We check to see if we have a query value coming in, if we do, we limit our query to names that start with the query. If not, we return them all.  Also note, that we check to see if this is an Ajax call. If someone has javascript off, we still want this to be functional.

Compile the project so we’ll have the model types available to us when we create our partial view.

Right click on Views/Home and add a View.  We’ll call this ProductSearchResults:

image

We’ll simplify the view down a bit to just include a few fields.  Of course, ideally we’d use a view-model for this to limit what data is even available, but that’s not the point of this post.

<%@ Control Language="C#" 
Inherits="System.Web.Mvc.ViewUserControl<IEnumerable<AWAjaxDemo.Models.Product>>" %>

    <table>
        <tr>
            <th>
                Name
            </th>
            <th>
                ProductNumber
            </th>
            <th>
                Color
            </th>
            <th>
                StandardCost
            </th>
            <th>
                ListPrice
            </th>
           
        </tr>

    <% foreach (var item in Model) { %>
    
        <tr>          
            <td>
                <%: item.Name %>
            </td>
            <td>
                <%: item.ProductNumber %>
            </td>
            <td>
                <%: item.Color %>
            </td>
            <td>
                <%: String.Format("{0:F}", item.StandardCost) %>
            </td>
            <td>
                <%: String.Format("{0:F}", item.ListPrice) %>
            </td>
           
        </tr>
    
    <% } %>

    </table>



So, now we have a simplified partial view.

Now we’ll add our main view.  Right-click on the View/Home node and add a strongly typed empty view.  Base it on the AWAjaxDemo.Models.Product type that we did for the partial view.

image

Replace the default code with this:

<%@Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master"
Inherits="System.Web.Mvc.ViewPage<IEnumerable<AWAjaxDemo.Models.Product>>"%>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
  
Product Search
</asp:Content>
<
asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <
script src="../../Scripts/MicrosoftAjax.js" type="text/javascript"></script>
    <
script src="../../Scripts/MicrosoftMvcAjax.js" type="text/javascript"></script>
    <
h2>
      
ProductSearch</h2>
  
<% using(Ajax.BeginForm("ProductSearch", new AjaxOptions { UpdateTargetId = "results"}))
       { %>
    Search: <%=Html.TextBox("query")%> <input type="submit" value="Go" />
    <
div id="results">
  
<% Html.RenderPartial("ProductSearchResults", Model); %>
    </div>
  
<%} %>
</asp:Content>

You’ll notice that the two Ajax scripts are referenced.  They are added to mvc 2 applications by default.  The other thing to notice is how the form is constructed.  Normally the Html.BeginForm extension method is used. Here we are using the Ajax.Begin form method and passing it a new instance of AjaxOptions specifying the target to be updated. In our case, the target is the div with the id result.  Our ProductSearchResults partial view will be rendered there after the Ajax call.

That was pretty easy … of course in a production environment, you’d want to be using caching to reduce the database calls.

Technorati Tags: ,
Tuesday, May 04, 2010 1:56:30 AM UTC  #    Comments [0] -
mvc | Visual Studio
# Monday, May 03, 2010

So I installed Visual SVN the other day on the recommendation of my good friend Paul Mehner and the setup was amazingly simple and with the client ($49 USD), the integration with VS2010 is great!

image

Get nice color coded icons showing the state of the files.

And it’s own toolbar.

image

Technorati Tags:
Monday, May 03, 2010 5:32:56 PM UTC  #    Comments [0] -
Visual Studio
# Wednesday, April 14, 2010

One of the exciting things about mvc2 are Templated Helpers. Templated helpers allow you to create a template for any type – your own or a system type.

Let’s say we have a very simple model for a contact page.  Our model will be called ContactModel:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ComponentModel.DataAnnotations;

namespace EliteCodersLLC.com.Models
{
    public class ContactModel
    {
        [Required]
        public string Email { get; set; }

        public string Phone { get; set; }

        [Required]
        public string Inquiry { get; set; }

        [Required]
        public string Name { get; set; }
    }
}

We pulled in the DataAnnotations namespace so we could add some simple required validation for the class.  When we use the tooling built into Visual Studio to add a view by right-clicking in the controller action, we end up with a a view like so:

<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<EliteCodersLLC.com.Models.ContactModel>" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
    Contact
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <div id="paper">
    <div>
        <h2>
            Contact</h2>
        <% using (Html.BeginForm())
           {%>
        <div class="editor-label">
            <%= Html.LabelFor(model => model.Email) %>
        </div>
        <div class="editor-field">
            <%= Html.TextBoxFor(model => model.Email) %>
            <%= Html.ValidationMessageFor(model => model.Email) %>
        </div>
        <div class="editor-label">
            <%= Html.LabelFor(model => model.Phone) %>
        </div>
        <div class="editor-field">
            <%= Html.TextBoxFor(model => model.Phone) %>
            <%= Html.ValidationMessageFor(model => model.Phone) %>
        </div>
        <div class="editor-label">
            <%= Html.LabelFor(model => model.Inquiry) %>
        </div>
        <div class="editor-field">
            <%= Html.TextAreaFor(model => model.Inquiry) %>
            <%= Html.ValidationMessageFor(model => model.Inquiry) %>
        </div>
        <p>
            <input type="submit" value="Submit" />
        </p>
        <% } %>
        <div>
            <%=Html.ActionLink("Back to List", "Index") %>
        </div>
        </div>
    </div>
</asp:Content>

However, what we can do is pull all the editor type stuff out and put it into a templated helper.  First thing we want to do is created a directory under Views/Shared called EditorTemplates. This will be where any shared editor templates will reside.  Of course, if you only want the template to be used for a particular set of views, put it in that folder.  For instance, if it should only be used from the Home controller and Views, you would create the EditorTemplates directory under Views/Home.

image

In there we want to create a partial, strongly typed view giving it the name of the type it will be the editor for.  In our case it will be for the ContactModel class, so it will be called ContactModel.ascx.

We’ll put all the editor markup in this new view.  This view can be customized in any way and will be used whenever Html.EditorForModel() is called when the Model is a ContactModel.

<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<EliteCodersLLC.com.Models.ContactModel>" %>
    <div class="editor-label">
        <%= Html.LabelFor(model => model.Email) %>
    </div>
    <div class="editor-field">
        <%= Html.TextBoxFor(model => model.Email) %>
        <%= Html.ValidationMessageFor(model => model.Email) %>
    </div>
    <div class="editor-label">
        <%= Html.LabelFor(model => model.Phone) %>
    </div>
    <div class="editor-field">
        <%= Html.TextBoxFor(model => model.Phone) %>
        <%= Html.ValidationMessageFor(model => model.Phone) %>
    </div>
    <div class="editor-label">
        <%= Html.LabelFor(model => model.Inquiry) %>
    </div>
    <div class="editor-field">
        <%= Html.TextAreaFor(model => model.Inquiry) %>
        <%= Html.ValidationMessageFor(model => model.Inquiry) %>
    </div>

And now our Home/Contact.aspx page simply has this inside the form:

        <% using (Html.BeginForm())
           {%>
        <%= Html.EditorForModel() %>
        <p>
            <input type="submit" value="Send" />
        </p>
        <% } %>

 

The same thing can be done for display templates as well. Do the same process but use DisplayTemplates as the folder name.

Happy coding!

Technorati Tags:
Wednesday, April 14, 2010 4:08:08 AM UTC  #    Comments [0] -
mvc
# Sunday, April 11, 2010

Well, VS 2010 launches tomorrow, and I’m really excited to get my hands on the final bits.  I’ve really enjoyed working with the beta and the RC.  MSDN is down for maintenance until tomorrow morning, probably beefing up the infrastructure to handle the influx of requests that will undoubtedly be coming tomorrow.

There are some wonderful wallpapers to be had here. I set mine to #3.

Technorati Tags: ,
Sunday, April 11, 2010 4:00:18 PM UTC  #    Comments [0] -
.NET | Visual Studio
# Monday, March 29, 2010

Today I’m going through Scott Hanselman’s recent OData post regarding StackOverflow.

I’m also going through a jQuery tutorial.

Monday, March 29, 2010 1:54:52 PM UTC  #    Comments [0] -

Found this one out by accident.  Put the mouse over the top or bottom border as if you are going to stretch the window up or down.  Then double click.  The window will snap full height keeping the current width.  Pretty cool!

Technorati Tags:
Monday, March 29, 2010 12:18:04 AM UTC  #    Comments [0] -
Windows 7
Archive
<July 2010>
SunMonTueWedThuFriSat
27282930123
45678910
11121314151617
18192021222324
25262728293031
1234567
About the author/Disclaimer

Disclaimer
The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.

© Copyright 2012
George Handlin
Sign In
Statistics
Total Posts: 51
This Year: 0
This Month: 0
This Week: 0
Comments: 9
All Content © 2012, George Handlin
DasBlog theme 'Business' created by Christoph De Baene (delarou)