Friday, 13 February 2009

ASP.NET page validation and redirection to a new page

I was working on the ASP.NET web site where users register using form and get redirected to a different page on pressing submit button. Easy way to redirect to a new page is to use PostBackUr property of the button.

<asp:Button runat="server" ID="BtnSubmit"  Text="Submit" PostBackUr="newpage.aspx" />

Unfortunately this does not work if we need to handle button OnClick event. Solution is to use Server.Transfer or Response.Redirect of the Page control.

protected void BtnClick(object sender, EventArgs e)
{
        if (Page.IsValid)
        {
                // Do something ...

                Response.Redirect("newpage.aspx");
        }
}

Page.isValid is true if all validators on the page and in web controls returned valid. A very good explanation about the difference between Server.Transfer and Response.Redirect can be found in the link below.

Server.Transfer Vs. Response.Redirect

Friday, 6 February 2009

Getting Started with AJAX development and AJAX Control Toolkit

Developers who use Visual Studio 2008 know that AJAX already built into ASP.NET for .Net 3.5 Framework. All they need is to get AJAX Control Toolkit.

AJAX Control Toolkit .Net 3.5

How Do I: Get Started with ASP.NET AJAX? is an excellent video that helps to get started.

AJAX for .NET 2.0

If you are developing pure .Net 2.0 ASP.NET website or still using Visual Studio 2005 you need to get AJAX 1.0 and  AJAX Control Toolkit for .Net 2.0.

ASP.NET AJAX 1.0

ASP.NET 2.0 AJAX Templates for Visual Studio 2008

AJAX Control Toolkit for .NET Framework 2.0, ASP.NET AJAX 1.0

AJAX Tutorials and Documentation

AJAX Website has extensive number of Tutorials and Control Toolkit has a sample website that will be very helpful to make learning curve shorter.

ASP.NET AJAX Videos

ASP.NET AJAX Documentation

AJAX Control Toolkit Tutorials (C#)

ASP.NET Learning Centre

Deployment of AJAX enabled websites

Once development is finished and project need to be deployed to testing or production servers, install ASP.NET AJAX 1.0 on the server if you are deploying ASP.NET 2.0 website. ASP.NET 3.5 website will require only .NET 3.5 runtime installed on the server. There is no need to install AJAX toolkit as long as toolkit DLL is distributed in bin folder.

Wednesday, 28 January 2009

ASP.NET Access DB write problem

Recently I was working on simple ASP.NET website that had to update Access Database. Everything was fine during development when I was using ASP.NET Development Server created by Visual Studio. Later when I connected with Internet browser to http://localhost/mywebsite/Default.aspx I started getting two kind of unhandled exceptions on Database insert and update.

Microsoft JET Database Engine error '80004005'

The Microsoft Jet database engine cannot open the file 'C:\DB\YourDatabase.mdb'. It is already opened exclusively by another user, or you need permission to view its data.

or this one

Microsoft JET Database Engine error '80004005'

Operation must use an updateable query.

After looking on the internet I found a couple of links that shed some light on this problem.

How Do I Fix ASP 80004005 errors? - Imar.Spaanjaars.Com

An unhandled exception may occur when you try to connect to an Access database from an ASP.NET worker process.

I tried to fix a problem by following instructions on these pages, unfortunately adding permission for IUSR_MyComputerName system user to access DB folder did not make a difference. The quick and easy (and NOT RECOMMENDED for production installation) solution is to add Everyone to access to DB folder and write to database. I want to repeat that this is not a good solution for security reasons, my preference is to try to change an account under which IIS service is running. I will post my solution later once I get it working.

References

How to configure file sharing in Windows XP

Friday, 19 December 2008

Download Windows Updates for offline install

Recently I performed a complete reinstall of my desktop computer and now require to download all windows updates again. With only 1Gb of available download and upload a month it will be easy to quickly use up all of it if with these updates. For these who want to save distributable copies of patches Microsoft provides two web sites to download updates from.

It is possible to find windows updates for XP, Vista and any other windows flavour, just search for KB# like (KB956391) which is shown in Automatic Updates window.

WindowsUpdates