Dave Hawes Blog
It is all about delivering

When explicitly binding asp:ListView the first item’s EditItem == null in the ItemUpdating event

July 27, 2009 22:51 by davehawes

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!


Tags:
Categories: ASP.net
Actions: E-mail | Permalink | Comments (2) | Comment RSSRSS comment feed

When ASP.net, Url re-writing and search engines do not play nicely

March 28, 2009 21:33 by davehawes

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...


Tags:
Categories: ASP.net | SEO
Actions: E-mail | Permalink | Comments (4) | Comment RSSRSS comment feed

MVC.net and YUI (Yahoo UI) Brown bag session on 14th March

March 11, 2009 13:36 by davehawes

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...


Tags:
Categories: ASP.net | MVC | C# | Software Developement
Actions: E-mail | Permalink | Comments (6) | Comment RSSRSS comment feed

Success in using Blogengine.net as a lightweight CMS

February 6, 2009 09:47 by davehawes

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...


Saving control values when using a callback to upload a file

January 21, 2009 00:37 by davehawes

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";
        }
    }
}
 
 

Tags:
Categories: ASP.net | charity | DevExpress
Actions: E-mail | Permalink | Comments (0) | Comment RSSRSS comment feed

ASP.net MVC - can't wait to give it a whirl

September 6, 2008 08:01 by davehawes

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...