Tuesday, May 12, 2009

Using the Repeater as the out-of-box controls

Usually when you want to create some kind of listing of data, with items that can be added, updated and deleted, you can use the out-of-box GridView control altogheter with FormView, ListView and DetailsView controls.
Since you almost don't need to write any code at all, these controls works fine for doing quick solutions with non-complicated data, (like fetching data from one table).
But when it comes to more complicated data structures it becomes more difficult to maintain these controls.
In these situations it is recommended to have more control, by knowing what is going on under the hood. This is where the Repeater control comes in handy.

In the following six upcoming posts I will show you how to use the Repeater control to establish almost the same things as you can do with the out-of-box controls plus a little more.

Here are the following parts that will be described:

1. Simple Repeater

2. Add, edit and delete Repeater

3. Multi-Row update Repeater

4. Sorting Repeater

5. Paging Repeater

6. All-In-One Repeater

In the next post we will go through the Simple Repeater.

Thursday, May 7, 2009

Minimizing script injection with Server.HtmlEncode

In some occasions part of your web application might need to have validateRequest turned off to allow users to input specific tags needed for their business. This composes a security risk that needs to be treated. One way to solve this is to use the Server.HtmlEncode().

In this small example we have an aspx page that has its valiateRequest turned off:

With the following desing:

If we type in a java script block and presses "Unsafe submit" button, the script will execute.

Code behind:

To prevent the injected script from running we can use Server.HtmlEncode() as follows :

Now when pressing button "Safe submit" the script will be encoded to html and will be unharm for the user:

For complete source code click here.

Saturday, May 2, 2009

Selecting top, bottom and in between rows in sql

In this post I am going to show how you in an easy way can select top, bottom and in between rows from a table. The table that I am using is a fictitious Customer table with primary key name CustomerID.

1. Selecting the first 10 rows from Customer table:

SELECT TOP 10 * FROM Customer ORDER BY CustomerID

The code above is quite straight forward using the "TOP" keyword to picking out the first 10 rows.

2. Selecting the bottom 10 rows from Customer table:


In this code we also use the "TOP" keyword but now we change the sort order to "DESC" (descenging) letting us picking out the 10 rows from the bottom.

3. Selecting rows between 10-20 from Customer table:

SELECT TOP 10 * FROM Customer WHERE CustomerID IN
SELECT TOP 20 CustomerID FROM Customer ORDER BY CustomerID

In the code above we use nestled query to achieve the extraction of row 10-20. The inner query picks out row 0-20 and the outer query picks out row 10-20 from the inner query.

Friday, February 20, 2009

Saving sessions to sql database

Using sessions on a web site is very flexible. Normally the session states are saved on the webserver. But in some occasions you need to be sure that the session state is preserved if the web application is restarted, or when sessions are used on multiple web servers in a web farm.

In this article I will describe how to configure and use sessions by saving them to an SQL Server database.

Note! There are however some limitations with saving sessions to database:
-Firstly you can't save primitive data types like int, string, double etc. You can only save custom objects.
-Secondly the custom objects that you save have to be serialized before you save them to the session.
-Thirdly you have to deserialize the data when retrieving the session.

Creating the ASPState database

Start creating the ASPState database by running a script in command prompt.

1. Open a command prompt.
2. Go to folder C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727

3. Type in the following command: aspnet_regsql.exe -S sqlservername -E -ssadd -sstype p (where sqlservername is the name of your sql instance)

4. Click Enter.
5. The database should now have been creted.

An alternative way to generate the ASPState database is to run the script InstallSqlState.sql which also resides under folder
C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727. (Note! This is however not recommended.)

Changing the web.config

1. You also need add/change your web.config file. Add the sessionstate tag as below:

2. sqlservername is the name of your sql instance. Also note that I have put a timeout for the session to 35 minutes.

Saving and loading sessions to database

1. All custom classes/objects that needs to be saved as a session to the database needs to be serializable classes. This is simply done by adding the [Serializable] keyword before the class declaration.

2. We will also need to create two methods that serialize and deserialize our custom class.

3. Now we can save and load the session with the following code:

For complete source code click here.

Tuesday, February 10, 2009

Resetting INSP Service on VW Passat/Audio A4

If you have a VW Passat/Audio A4 of model 1996-1999 and you get the message INSP Service every time you switch the ignition on. You either need to send the car to an authorized service center for an annual service inspection or you can reset the message yourself.

In this article I descibe how you can reset the INSP Service message that pops up in the speedometer display every time you switch on the ignition. (Note! It only works on VW Passat/Audio A4 of model 1996-1999):

1. Press and hold the button that is below your speedometer (right button), at the same time switch the ignition on.

2. The message OIL Service should appear.

3. Release the right button (below speedometer).

4. Press the right button again and the message INSP will appear.

5. Release the right button (below speedometer).

6. Turn the left button (below the tachometer) to the right. INSP message will disappear.

7. Switch the ignition off.

Try switching the ignition on again. Now the INSP Service message should have disappeared.

Monday, February 9, 2009

Fixing iPhone - Could not activate cellular data network. You are not subscribed to a cellular data service.

I bought a new iPhone 3G last week, and I was very satisfied with the phone.

But I had some problems when trying to access internet through my 3G sim card (with WLAN disabled). I kept getting the message:

Could not activate cellular data network. You are not subscribed to a cellular data service.

After a couple of tries I found the solution as follows:

1. Click on Settings --> General --> Network --> Cellular Data Network.

2. Under APN type in your provider, in my case I typed in:


3. After doing this I was able to access Internet without any error messages.

Tuesday, February 3, 2009

Part 3 - Create a bootable usb 'light windows' a.k.a Bart PE

This is the third and last part of booting from usb flash stick.

In this part I will describe how to create a bootable usb 'light windows' a.k.a Bart PE.


1. For this you will need an usb flash stick. I myself tried a No name usb 2GB and it worked fine.

2. You will also need the following files:

-pebuilder3110a (official site download)

-Windows 2003 Server SP1 or srsp1 (two extracted files from the win 2003 sp1)


1. Save the files from above to a place on your disk for example C:\

2. Extract the pebuilder3110a.zip to the folder c:\pebuilder3110a

3. In folder c:\pebuilder3110a create a new folder named: srsp1 (this will be used later)

4. Open a command-prompt and type in the following command to extract the files of Windows
2003 sp1:

WindowsXP-KB835935-SP2-ENU.exe -x

5. A message box will appear asking you to select a directory for extraction, choose:


6. Copy the file setupldr.bin

-from C:\win2003sp1\i386

-to C:\pebuilder3110a\srsp1

7. Expand and copy ramdisk.sys by running the command:

expand -r C:\win2003sp1\i386\ramdisk.sy_ C:\pebuilder3110a\srsp1

8. Go to the folder: C:\pebuilder3110a Start BartPE by double clicking pebuilder.exe

9. A windows will appear. Select source to your windows xp cd (in my case F: was my cd letter):

10. If your Windows XP cd has Service Pack 2 included then you need to enable a plugin.
Click on the Plugins button and enable "RpcSS needs to launch DComLaunch Service First - SP2 only" in the list.

11. Click close when done.

12. Click Build, to start building the image that will be used for your usb.

13. If asked to create directory, click Yes.

14. Click Close when done.

15. Plug in your usb stick if you haven't already done that.

16.After building is finished go to command-prompt and type in:

pe2usb -f G: (where G: is my usb drive letter)

17. Type in YES when asked to. This will start creation of your bootable usb stick.

18. When done close the command-prompt window and take out your usb stick. You should now be able to boot from your usb stick.

This concludes the final part, Part 3 - Create a bootable usb 'light windows' a.k.a Bart PE.
By this I have now described three ways of using a usb flash stick booting. I hope you have had good use of this reading.
get a counter