Wednesday, 30 January 2008

Client-side validation controls

Client-side validation controls (e.g. RegularExpressionValidator) are really good for spotting incorrect input before any server-side processing takes place because the page is prevented from doing a postback.

What if you override the client click event (OnClientClick) of a button that is associated with one or more validation controls. Would you expect a similar behaviour? Wrong! The custom script is executed regardless of the validation.

The desired outcome of the following example is to get a popup when the button is clicked if the text box isn't empty:

<asp:TextBox ID="tbName" runat="server" ValidationGroup="Name" />
<asp:Button runat="server" Text="Submit" OnClientClick="javascript:alert( 'hello world' );" ValidationGroup="Name" />
<asp:RequiredFieldValidator runat="server" ControlToValidate="tbName" Text="*" ValidationGroup="Name" />

The actual outcome is a popup even if the text box is empty. To make sure the page is valid, call Page_ClientValidate to update Page_IsValid (true/false) and add a condition around your script:

<asp:TextBox ID="tbName" runat="server" ValidationGroup="Name" />
<asp:Button runat="server" Text="Submit" OnClientClick="javascript:Page_ClientValidate(); if ( Page_IsValid ) { alert( 'hello world' ); }" ValidationGroup="Name" />
<asp:RequiredFieldValidator runat="server" ControlToValidate="tbName" Text="*" ValidationGroup="Name" />

Tuesday, 29 January 2008

Tags inside PRE

PRE tags are used to format text; linebreaks, spaces and tabs are all recognised from the source instead of being ignored. One thing they don't display (without a small tweak) is tags (e.g. <test>) - the angle brackets and any content will be omitted but there is a solution. Simply replace the first angle bracket with &lt; (e.g. &lt;test>).

Saturday, 26 January 2008

Change Page Language in EPiServer

After a previous post about changing an existing page's page type in EPiServer, I've now found out how to change an existing page's language.

At Esendex, we have different websites for each country in EPiServer. Originally, we started with a single UK website which was simply copied to create ones for Australia, France and Spain. This meant that all of the pages had been created in English (default) instead of the respective country languages. Instead of creating further instances of the pages, we wanted to change the existing ones to save time. This also helped us with the our content mirroring; we have servers in the respective countries to host our global sites. These servers should only have a copy of the website in the appropriate language. We found it difficult mirroring English pages into French copies and we didn't want multiple instances on these servers.

declare @PageID int
declare @OriginalLanguageBranchID int
declare @NewLanguageBranchID int
declare @NewLanguageID nvarchar( 3 )

set @PageID = X
set @OriginalLanguageBranchID = Y
set @NewLanguageBranchID = Z
set @NewLanguageID = '' -- e.g. 'FR'

update tblPageLanguage
set fkLanguageBranchID = @NewLanguageBranchID, fkLanguageID = @NewLanguageID
where fkPageID = @PageID

update tblPage
set fkMasterLanguageBranchID = @NewLanguageBranchID, fkLanguageID = @NewLanguageID
where pkID = @PageID

update tblProperty
set fkLanguageBranchID = @NewLanguageBranchID
where fkPageID = @PageID and fkLanguageBranchID = @OriginalLanguageBranchID

exec editPageVersionList @PageID = @PageID, @SID = NULL

Simply replace X with the page ID, Y with the original (current) language branch ID and Z with the new language branch ID. The new language ID is respective to the new language branch ID. These ID values can be found by querying the tblLanguage and tblLanguageBranch tables.

It might sound obvious, but before running this script on a page, make sure no instances for the new language already exist otherwise concurrency exceptions will be thrown.

Monday, 21 January 2008

Challenging challenges

Are you finding it hard to complete some of the challenges on Call Of Duty 4? With the help of a friend, you can host a Cage match (1 on 1) and organise different scenarios to achieve maximum XP and ultimately increase your rank. One of the best (but most boring) examples is head shot kills - you and your friend take it in turns to shoot each other in the head by continuously meeting at a specified location.

Instructions:
  • Enter the pregame lobby

  • Send an invite to your friend but tell him/her not to accept - simply get ready to accept

  • Find a Cage match

  • As soon as you start matchmaking, tell your friend to accept the invitiation - he/she will then join the lobby and the match will begin
  • Thursday, 10 January 2008

    Change Page Types in EPiServer

    I work for a company called Esendex where I help development and maintain their web projects. The main website uses a CMS called EPiServer, allowing non-technical people to create, edit and publish web pages. The system uses custom page types that are based on real *.aspx files known as templates. The templates specify the layout of the dynamic content stored in EPiServer's database which is editable in the CMS. When a page is loaded, the template requests the data and inserts each part into the relevant position.

    Pages in EPiServer only exist virtually - there is no physical file for their existence. They are simply based on one of the page types and the database keeps a record of any respective data. A single template can be used to create several pages that will all look the same but contain different information. This is a nice feature but what happens if a page is created against template X and we want to use template Y in the future? We asked the same question to an EPiServer specialist who didn't really have an answer. The best he could come up was to update the database manually; in other words - there is no built-in functionality. Below is some SQL that can be run against the EPiServer database in order to modify an existing page's page type:
    declare @PageID int
    set @PageID = X

    declare @PageTypeID int
    set @PageTypeID = Y

    declare @LinkURL nvarchar( 255 )

    select @LinkURL = [Filename] from tblPageType where pkID = @PageTypeID

    set @LinkURL = @LinkURL + '?id=' + cast( @PageID as nvarchar )

    update tblPage set fkPageTypeID = @PageTypeID, LinkURL = @LinkURL where pkID = @PageID

    update tblWorkPage set LinkURL = @LinkURL where fkPageID = @PageID

    delete from tblWorkProperty
    where fkWorkPageID in ( select pkID from tblWorkPage where fkPageID = @PageID )

    Simply replace X with the page ID and Y with the page type ID.

    Monday, 7 January 2008

    Hey I'm so cool! I've just signed up for this...

    Hey I'm so cool! I've just signed up for this great new service from Esendex where I can blog all day long from my mobile phone for free!


    Mobile post from the Esendex BlogIt service