Tuesday, May 12, 2009
Using the Repeater as the out-of-box 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 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:
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:
SELECT TOP 10 * FROM Customer ORDER BY CustomerID DESC
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
) ORDER BY CustomerID DESC
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
In this article I will describe how to configure and use sessions by saving them to an SQL Server database.
1. Open a command prompt.
C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727. (Note! This is however not recommended.)
Tuesday, February 10, 2009
Resetting INSP Service on VW Passat/Audio A4
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.
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:
internet.telenor.se
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
In this part I will describe how to create a bootable usb 'light windows' a.k.a Bart PE.
Requirements:
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)
How-to:
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:
C:\win2003sp1
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.
Tuesday, January 13, 2009
Part 2 - Install Windows XP from a usb flash
In this part I will describe how to enable installation of Windows XP from an usb stick.
Requirements:
1. For this you will need an usb flash stick. I my self tried a Sandisk USB 4GB and it worked fine.
2. You will also need the following three files:
-PeToUSB
-usb_prep8
-bootsect
3. A Windows XP CD or a mounted iso of Windows XP.
4. Further you need to have a computer that allows booting from an usb stick. (Almost all newer computers especially laptops allows booting from usb.) You will also need to set your usb to be the first boot priority in your computers BIOS.
How-to:
1. Save the three files from above to a place on your disk for example C:\bootusbxp.
2. Extract usb_prep8.zip, PeToUSB_3.0.0.7.zip and boot bootsect.zip to the same folder as the (ie C:\bootusbxp). It should look like:
3. Move the file PeToUSB.exe to the folder usb_prep8.
a) Go into the folder PeToUSB_3.0.0.7 and cut the file PeToUSB.exe.
b) Paste the file PeToUSB.exe into the folder usb_prep8. It should now look like:
4. In the folder usb_prep8 you will find a file named usb_prep8.cmd.
5. Double-click this file and a command-prompt will appear:
6. Press any key to continue. This will open the PeToUSB formatting tool.
In the drop down list you will see you USB flash drive (In my case SanDisk U3...)
7. Press Start to begin formatting the usb flash stick. A question will appear saying if you want to Continue? Press Yes.
8. Yet one more question appears asking if you want to continue. Click Yes to continue.
9. If everything goes as expected a message box will appear saying that the operation was completed successfully (ie your usb flash was successfully formatted).
Note! Don't close any windows, let the PeToUSB and usb_prep8.cmd windows stay open.
10. Next step is to configure the boot sector so that the usb will be able to boot. This is done with the BootSect.exe (C:\bootusbxp\bootsect).
a) Click Start => Run...
b) Type in the word: cmd
c) Click OK. (A command-prompt window will appear)
11. We now need to move to the folder where the BootSect.exe file exists. (ie C:\bootusbxp\bootsect). Do this by typing and pressing enter after each command:
a) type: cd\
b) press: Enter
c) type: cd bootusbxp\bootsect
d) press: Enter
e) type bootsect.exe /nt52 G: (where G: is the usb flash stick)
f) press: Enter
g) The bootcode should now have been updated. See screenshot:
h) You can now close this window.
12. Before you continue, insert your Windows XP CD into your optical drive. Then return to the PeToUSB windows if it is still open and click on the Close button. The command-prompt window should now appear with the following menu alternatives:
13. In this prompt there are three steps that are important: 1, 3 and 4. We will need to complete each step. Start by setting the path to XP Setup Source (ie your Windows XP CD path). Do this by clicking:
a) 1
b) Enter
14. A window for browsing will appear. Select the drive for your Windows XP CD. (In my case F:) and click OK.
15. Next we need to set the target for the usb flash stick.
a) Type in: 3 and press Enter.
b) Type in: G (Here you should type in the letter of your usb in my case G). Press Enter.
16. The final step is to create the windows template and start copying installation files to our usb flash.
a) Do this by typing: 4 and pressing Enter.
b) A question will appear if we want to format the virtual drive (Y/N). Type Y and press Enter.
c) Then press any key to continue....it will now copy files from your Windows CD to the virtual drive.
d) After that a message box will ask if you want to copy TempDrive files to USB taking 15 minutes. Click Yes to start copying files to your usb flash.
e) On question if you want usb stick to be preferred boot drive U: Click Yes
f) Further click Yes to unmount drive.
g) When finished click any key in the command prompt to close the window.
This completes the steps needed for enable installation of Windows XP from an usb stick. Next I will describe how to install Windows XP from the usb.
The installation procedure differs a little bit from an usual installation. First you need to note that the usb flash needs to stay inserted in the computer during the whole installation of Windows XP. Secondly you will see a new menu displayed when booting from the usb flash. Below I continue describing the installation process.
18. Start your computer with the usb inserted. A menu asking to start from TXT Mode or GUI Mode will appear. Select TXT Mode.
The computer will then restart two times during the installation process. The same menu as above will appear, but this time you should select GUI Mode on both occasions.
19. After the installation has finished you can remove the usb flash stick.
This concludes the Part 2 - Install Windows XP from a usb flash. In the next part I will describe how to boot up a light Windows XP a.k.a Bart PE directly from the usb flash.
Sunday, January 11, 2009
Part 1 - Create a bootable usb flash
Today also more and more laptops are being delivered without an optical drive not to speak of the tiny EeePC's.
This insertion will consist of three parts:
1. In the first part I will describe how to "Create a bootable usb flash".
2. In the second part I will describe how to create and "Install Windows XP from a usb flash".
3. And in the third and final part I will describe how to "Create a bootable usb 'light windows' a.k.a Bart PE".
Create a bootable usb flash
Requirements:
1. For this you will need an usb flash stick that aren't bigger then 2GB (since this is the limit). I my self tried a NoName USB 2GB and it worked fine.
2. You will also need the following two files:
-HP USB Disk Storage Format Tool (This tool enables you to format your usb flash stick)
-Dos (Includes dos files needed when making the format)
3. Further you need to have a computer that allows booting from a usb stick. (Almost all newer computers especially laptops allows booting from usb.) You will also need to set your usb to be the first boot priority in your computers BIOS.
How-to :
1. Save the two files from above to a place on your disk for example C:\bootusb.
2. Extract the file HPusbUtil.rar which contains the file HP USB Disk Storage Format Tool (HPusbUtil.exe).
3. Install the HP USB Disk Storage Format Tool by double clicking the file HPusbUtil.exe, and following the installation procedure.
4. Next extract the file dos.rar to a folder for example C:\bootusb\dos.
5. Now start the HP USB Disk Storage Format Tool either from the link on your Desktop or from the start menu. The tool will now open and you will see the name of your usb stick in the dropdownlist. Here you should set the following settings:
a) File system: FAT
b) Format options:
--Quick Format "unmarked" (you could also try marking Quick Format)
--Create a Dos startup disk....using DOS system files located at:
c) Browse for the Dos files that you extracted to C:\bootusb\dos by clicking the button [..]
It should all look like:
6. Click Start to begin the formatting of your usb stick.
7. After finishing the formatting click OK.
8. You should now have a bootable usb flash stick that are bootable on computers that allows usb booting.
In the next part I will go throught on how to create and "Install Windows XP from a usb flash".
Friday, January 9, 2009
Returning a relative path
Below is an example showing four links, the first one is a static link, the second actually fails as a link, and the last two links shows how to use ResolveClientURL and ResolveURL:
Wednesday, January 7, 2009
Adding user control reference in web.config
Here I have registered two custom user control and also the AjaxControlToolkit inside the web.config (see code line 8-10).
One problem that might arise when doing this approach is when you need to nestle one control inside another control. This will generate a compiling error saying something like:
The page '/MyProject/App_UserControls/Personnel.ascx' cannot use the user control '/MyProject/App_UserControls/DateSelector.ascx', because it is registered in web.config and lives in the same directory as the page. C:\My Projects\App_UserControls\Personnel.ascx
A solution for this problem is to re-register the DateSelector user control inside the Personnel.ascx file as the following code (see code line 4):
Friday, January 2, 2009
A new blog starts...
In life you always learn things that might be useful for yourself and others, things that you wished that you wrote down and collected somewhere. So that you could reuse that information later when you are in need of it.
The problem normally is that you either don't remember the information or have forgotten where you wrote it. In this blog I will try to bring up topics I find useful, tips & tricks and things that you might get stuck with spending hours to solve. For the moment I don't really know the exact topic range that I will discuss. It might be all from hacking a website to baking a cake :) , anyway I hope that you will have fun and benefit from reading my blog. Welcome!
Kind Regards
Hassan El-Saabi