Tuesday, April 29, 2008

How to prevent Post back event when page refresh

One annoying behavior of ASP.NET pages is a replay of postback events when user hit refresh (F5) in browser.
This behavior is easily reproducible:
Place ASP button on Web Form
1. Add some code to Button_Click event
2. View page in browser
3. Check that your code being executed when you hit button
4. Refresh page and observe that your code being executed once again

The are a couple of solutions to get around this. But the easiest way is like this,

At the end of eventhandler, ie. button click, itemcommand, insert a line of code.

Response.Redirect("thispage.aspx ");

Which means, just redirect to the same page.

Also, this can be used to disable Back button

Eric

Monday, April 7, 2008

Error when installing .NET Framework 3.0

Microsoft .NET Framework 3.0 has encountered a problem during setup.
Setup did not complete correctly.

occured while installing the .NET 3.0 redistrubutable (downloaded from here) on my PC running XP Pro SP (also with .NET 1.1 & 2.0).

After some investigation it turns out this error was caused when installing the WCF (Windows Communication Foundation) components - when trying to open the following registry key:

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Eventlog\Security\ServiceModel 3.0.0.0

I thought this was odd, because my user is a local admin - so in regedit (regedt32) I tried giving my user permissions to full control of this registry node... then reran the install - however to no avail - same error.

So, tried giving Everyone full control of this node - reran the install - and bingo, it worked!

For those of you who don't know - here's how:

1. Open the registry editor: Start - Run..., then enter "regedt32" (without quotes).
2. Navigate down to the node by opening each node in the heirarchy.
3. Right click on the node we're after (ServiceModel 3.0.0.0) and select Permissions
4. Click on Add, then enter "everyone" (no quotes) on the 'Select Users, Computers or Groups' dialog then click OK.
5. Back on the 'Permissions for ServiceModel 3.0.0.0' dialog select the user group Everyone, then make sure the Full Control checkbox has a tick, then click OK.

Thats it - now rerun the .NET 3.0 installation.