ASP.net »

[27 Jul 2009 | 0 Comments]

I have just had one of those weeks where nothing seems to be simple, now finally after countless hours of head scratching I think I have a solution to a problem that has dogged me for over a month now.

I am using an asp:ListView on the Online File Store of my http://www.skillbook.co.uk website (check it out, it’s free to sign up to!!). I decided to explicitly bind my data to the control rather than use the <%# Bind(“”) %> syntax for reasons that are not important. During testing we had reports that when saving an edit of the first item in a page an exception was being thrown the good old ‘object reference is not equal to an object’.

Back on the Dev environment I could not reproduce it. On the internal server I could not reproduce it. On the live server it was falling over like my 5 week old baby trying to stand when I clicked save.

I have found other people with this problem:

http://forums.asp.net/p/1275744/2424258.aspx#2424258

http://www.ureader.com/msg/14254035.aspx

but no solution. With the pressure on to fix this in the live environment I have finally found a solution that seems to work, and I’m afraid that it is phugly code.

With the listView.EditItem == null the answer for me was just to get the item out of the ListView using the index that is sent through as part of the ListViewUpdateEventArgs.

So instead of:

                 ASPxTextBox txtName = (ASPxTextBox)listView.EditItem.FindControl("txtName");

It becomes:

                 ASPxTextBox txtName = (ASPxTextBox)listView.Items[e.ItemIndex].FindControl("txtName");

 

I really hope this helps some people out there!

ASP.net, SEO »

[28 Mar 2009 | 0 Comments]

I have been using Url re-writing on my new website www.trainingcoursebooker.com to try and make friendly, human readable urls which are good for both people and search engines. There is a very subtle problem which I finally found and more importantly found a solution to.

Everything works great in testing and in live. However my email inbox was suddenly filled with notifications of errors on the site (I’ve written code that notifies me of all errors via email so I don’t have to check event logs). The important part of the exception message is:

Message: Cannot use a leading .. to exit above the top directory.

After a google around most of the answers seemed to be in the fact I would be using some kind of ../../../ notation to reference a stylesheet or something. After going through all my code multiple times I was sure it wasn’t that. I could not reproduce the errors and was very puzzled.[more]

It then occurred to me that it might not be a user browsing the site triggering this but a search engine crawling it. Sure enough with another google around I found this great article which found out that the browsers search engine crawlers use are not recognised by ASP.net and so my application was assuming that cookies are not supported which in turn causes this problem – for the full explanation please read the original article:

http://weblogs.asp.net/dfindley/archive/2006/09/05/Problems-with-RewritePath-and-Search-Engines_2E00_.aspx

I plumbed for creating a browser file to tell my application that the search engine browsers do support cookies which has fixed the problem and I haven’t received an error notification since :D

ASP.net, MVC, C#, Software Developement »

[11 Mar 2009 | 6 Comments]

I have managed to arrange Ian Crowther, an ex-colleague from Avanade, to come and do a brown bag session for me and my employees this Saturday 14th March at my office near Haslemere in the UK.

Ian has been working a lot with Microsoft’s MVC.net and Yahoo UI recently. He is going to give a presentation and then run a practical coding workshop on Microsoft’s MVC.net and Yahoo UI showing how to combine them to [more]produce some sexy looking websites. In the workshop we are going to attempt to re-implement a recent asp.net web forms project See The Link have been working on as an asp.net MVC.net project. I’m really excited to find out more about how this will work and what the result will be! If they are good I’m hoping to put the MVC.net version live instead of the original web forms version.

I know that it is short notice but I am opening up this event to any techies who might be interested. I have space for another 3 people so if you want to come along then ping me an email before this Friday. We will be starting at 10am on Saturday going onto whenever (hopefully be about 4-6 hours or so)!

ASP.net, BlogEngine.NET, C#, Software Developement »

[6 Feb 2009 | 6 Comments]

I have been using Blogengine.net for over a year now and have thought it is a great application. In this post I will tell you how I have successfully tweaked it to deliver a lightweight CMS system that I required. (I have published the source code at the bottom of this article)

At the time of writing I have successfully implemented a few websites powered completely with Blogengine.net:

http://www.seethelink.co.uk

http://www.petersfieldparish.org.uk

http://www.tonytinman.co.uk

http://www.marvelav.com

[more]Some of the things that I really like about Blogengine.net is how it can run just using Xml file out of the box and if you want to use a database you can. I like all the Search Engine Optimizations you get for free, I like how it implements semantic web technologies, I like how you can use 3rd Party tools to edit content (Live Writer for example)... the list goes on and on.

I have recently quit my job at Avanade and have setup my own website which I'm hoping to make a living out of. To pay the bills in the mean time I have been picking up small projects along the way. One of these was for a local parish church Petersfield Parish website. The main thing they wanted was a calendar of events & services which I completed using a standard asp.net website. They also wanted to allow members of the parish to contribute news items to the site which I thought was a perfect candidate for a blog solution.

I initially setup the blog with BlogEngine.net in a separate site and created an RSS reader to pull through the latest articles to the main site. However it wasn't the best solution as it would be nicer to have it all under one roof. I was also having problems with the site's webmaster has he used a Mac and Dreamweaver which was having all sorts of problems understanding the asp.net pages and breaking the site when new content was uploaded.

With these two problems to solve I decided to look at using BlogEngine.net to host all the content as well as the blog so the the webmaster could create and maintain content online with no risk of breaking the site and the contributors and blog articles would be under one roof.

I found this article about using Blogengine.net as a CMS solution but it seemed kind of fiddly as all the pages had to be standard.net pages with a usercontrol embedded in them for the content which would still leave me with my webmaster problem and I also thought this is essentially what Blogengine.net pages do.

So I decided to see if I could use the standard BlogEngine.net functionality to create the whole site. To my joy it was pretty straight forward to get 80% of the way there. I created a new theme based on the original site I had created and it looked the business. However there were a number of problems. The pages were in a random order and I wasn't sure how to get my funky calendar controls to work.

Fixing the page sort order was pretty straight forward as I just added a new property to the page entity in the XmlProvider to take an integer. I then amended the PageSiteMap class to sort the pages based on the new value and then Robert is your fathers brother.

I was still struggling with the calendar controls when I spied something in the BlogEngine.net source code

ERROR - UNABLE TO LOAD CONTROL : ~/path/usercontrol.ascx

Here was some standard functionality that I had not known about allowing me to drop usercontrols in to the generated pages. As I had already put my funky calendar controls in usercontrols so it was pretty straight forward to pop them in my new Blogengine.net pages. Then I had exactly what I wanted and a very happy customer (I had over delivered and undercharge.... again!)

Here is a link to the services usercontrol embedded in a page: http://www.petersfieldparish.org.uk/page/Services.aspx

The homepage has a few usercontrols, a couple pulling the last 3 articles contributed through as a summary and one showing today's services.

I then got my graphic designer to knock up a new theme for my company's, See The Link, website and very quickly I had a great looking website which is easy to maintain 100% created with Blogengine.net for us as well.

It has just re-enforced my view that is this a great product!

 

DaveHawes.BlogEngineTweaks.zip (12.59 kb)

ASP.net, charity, DevExpress »

[21 Jan 2009 | 0 Comments]

This is my ASP.net webform:

<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="AddPortfolioEvidenceControl.ascx.cs" Inherits="MyApplication.Web.RegisteredUsers.Portfolios.AddPortfolioEvidenceControl" %>
<%@ Register Assembly="DevExpress.Web.v8.2, Version=8.2.3.0, Culture=neutral, PublicKeyToken=9b171c9fd64da1d1"
    Namespace="DevExpress.Web.ASPxCallback" TagPrefix="dxcb" %>
<%@ Register Assembly="DevExpress.Web.ASPxEditors.v8.2, Version=8.2.3.0, Culture=neutral, PublicKeyToken=9b171c9fd64da1d1"
    Namespace="DevExpress.Web.ASPxEditors" TagPrefix="dxe" %>
<%@ Register Assembly="DevExpress.Web.v8.2, Version=8.2.3.0, Culture=neutral, PublicKeyToken=9b171c9fd64da1d1"
    Namespace="DevExpress.Web.ASPxUploadControl" TagPrefix="dxuc" %>
<%@ Reference VirtualPath="~/Default.master" %>
    
<dxcb:ASPxCallback ID="CallbackComplete" ClientInstanceName="Callback1" runat="server" OnCallback="CallbackComplete_Callback">
    <ClientSideEvents CallbackComplete="function(s, e) {uplImage.UploadFile();}" />
</dxcb:ASPxCallback>

<table>
<tr>
<td>Description:</td>
<td>
    <dxe:ASPxTextBox ID="txtEvidenceName2" runat="server" Width="400px">
    </dxe:ASPxTextBox>
</td>
</tr>
<tr>
<td>Valid From:</td>
<td>
<dxe:ASPxDateEdit ID="dtpValidFrom" runat="server" ClientInstanceName="dtpValidFrom" />
    
</td>
</tr>
<tr>
<td>Valid To:</td>
    
<td>
<dxe:ASPxDateEdit ID="dtpValidTo" runat="server" ClientInstanceName="dtpValidTo" />
</td>
</tr>
<tr>
<td>File:</td>
<td>
<dxuc:ASPxUploadControl ID="uplImage" runat="server" ClientInstanceName="uplImage"
    Size="35" OnFileUploadComplete="uplImage_FileUploadComplete"> 
    
    <ClientSideEvents FileUploadComplete="function(s, e) {refreshTabControl(); }"  />
    
</dxuc:ASPxUploadControl>


</td>
</tr>
<tr>
<td colspan="2">
<dxe:ASPxButton ID="btnUpload" runat="server" AutoPostBack="False" Text="Upload" 
        ClientInstanceName="btnUpload" Width="100px">
    <ClientSideEvents Click="function(s, e) { Callback1.PerformCallback(); }" />
</dxe:ASPxButton>
</td>
</tr>
</table>

 

This is my code behind:

 
using System;
using System.Drawing;
using DevExpress.Web.ASPxUploadControl;
using System.Web.UI;
using MyApplication.DAL.EntityClasses;

namespace MyApplication.Web.RegisteredUsers.Portfolios
{
    public partial class AddPortfolioEvidenceControl : MyAppUserControlBase
    {

        protected void CallbackComplete_Callback(object source, DevExpress.Web.ASPxCallback.CallbackEventArgs e)
        {
            PortfolioEvidenceBaseEntity evidence = new PortfolioEvidenceBaseEntity();
            evidence.Name = txtEvidenceName2.Text;
            evidence.ValidFrom = dtpValidFrom.Date;
            evidence.ValidTo = dtpValidTo.Date;
            
            Session["newUploadedEvidence"] = evidence;
            
        }

        protected void uplImage_FileUploadComplete(object sender, FileUploadCompleteEventArgs e)
        {
            e.CallbackData = SavePostedFile();
        }

        protected string SavePostedFile()
        {
            if (uplImage.IsValid && uplImage.HasFile)
            {

                PortfolioEvidenceBaseEntity evidence = (PortfolioEvidenceBaseEntity)Session["newUploadedEvidence"];
                

                try
                {
                   string resFileName = MapPath(UploadDirectory) + uplImage.fileName;
                   evidence.FileName =  resFileName;
                   evidence.FileType = uplImage.PostedFile.ContentType;
                   uplImage.SaveAs(evidence.FileType);
                }
                catch
                {
                    Session.Remove("newUploadedEvidence");
                    return "There was an error uploading file";
                }

                Session.Remove("newUploadedEvidence");
                evidence.Save();
                SelectedPortfolioItem.PorfolioEvedenceId = evidence.Id;
                SelectedPortfolioItem.Save();

                return "Completed";
                
            }
            return "No valid file found";
        }
    }
}
 
 

Software Developement, MVC, ASP.net »

[6 Sep 2008 | 0 Comments]

While I've had my head stuck in Crm for the last year I appear to have missed a very important release for ASP.net - Microsoft's Model View Controller (MVC).

The majority of people I meet think that ASP.net is Webforms. This is not true.

ASP.net is the framework and [more] Webforms is what Microsoft gives out of the box to developers to create webpages. If you wanted you could write your own rendering engines on ASP.net and not even touch webforms - go back to Asp classic or php style of creating pages. However I like how Webforms is declarative, easy to read and I'm able to leverage work done others in a simple way.

So now Microsoft have released a second 'out of the box' method to create webpages with ASP.net to developers which (from what I've read so far) is superior to the initial Webforms option.

Things that are getting me excited about MVC method are:

  • Easy to write unit tests
  • Much more control over html output to create semantically correct html therefore fully leverage the power of css and get higher ranking on Google ;)
  • Plugable Javascript / Ajax engines

So when I get home tomorrow I'll be downloading, installing and having a play as I think this will enable me to create better quality webpages using ASP.net.

http://www.asp.net/mvc/

http://weblogs.asp.net/scottgu/archive/2007/10/14/asp-net-mvc-framework.aspx