Monday, 24 March 2008

First, why would we need to find the Id of a UserControl element? When the html is built dynamically .Net will build the ids of a control that is in a UserControl and render the html ids dynamically. So if you wanted to refer to an item that was build in a user control and do something with it in JavaScript for example it wouldn't work as each time the page is rendered client side it could have different ids for that element.

Here is an example of how to get a handle on the correct id.

First lets create a simple UserControl.

Create a web project and add a web user control, calling it Results. On the Results.ascx page at a TextBox control so it looks something like below.

Set the Id of the TextBox to tbResults.

Now drop the control onto your default.aspx and preview in browser.

View the source code that has been rendered to the client. You should see something like this:

As you can see, rather than the id being as you set it 'tbResults' it has changed; in this case to include the name of the actual control. (obviously in this case every time you run this code it will produce the same, but in more complex controls perhaps using datagrids and multiple controls, it wouldn't quite be as simple).

So how can we gain access to the id when they are built dynamically so that we can programmatically do something with them.

Well lets go to your Results.ascx.cs page and add a bit more code.

We are going to create a property in the component so that we can get the name of the ClientID. We do this through the property available on each control called ClientID (simple really)

by outputting the property tbResultsId we were able to render the actual name of the id. So now you have a way of accessing the ids even when built dynamically. This is ideal when you are using JavaScript on rendered controls. Simple output the name in JavaScript using <%= Results1.tbResultsId %> everytime you need to write the name of the id.

Saturday, 22 March 2008

Stack and Heap

Before explaining value types, I think it is necessary to have a brief overview of memory.

There are two main types of memory types Stack and Heap (I'm sure the purists amongst you will explain that this is not the case and become very technical about it; however for this discussion of types it will suffice)

So what is the difference between the two.

Matthew Cochran has an excellent article to explain the difference, and is worth reading through.

What the above does is create a user-defined type of ExamDates that takes one parameter of a start date of the exam. 30 Days are added to the start date to get the exam date. We have overridden the ToString() method so that it always returns text about the exam date.

Enumerator Types

Enumerators are used to supply a list of choice. For example for an enumerator that uses the type of exam we are doing, we could use the following

A few of the staff at work are working towards the Microsoft Certified Professional Developer (MCPD) in Web Development. To achieve this they need to pass three exams. Two for the MCTS and one for the MCPD.

Thursday, 13 March 2008

I use Visual Studio 2005 and wanted to use IIS to test publishing a site to, but only have XP Home on my PC upstairs in my office so need to find a way to get IIS running on XP Home. I know I can hear you saying it now .... "You should upgrade to XP Professional". However let me explain why I didn't want to do this an my frustration.

I have a full (legit) version of Windows XP professional that I bought as an upgrade to a laptop (this has since died and is now in little pieces, but that's another story!). As I have an upgrade the most logical thing to do is upgrade my XP Home to XP professional.

Here is my dilemma - The XP Professional is SPK 1 and the XP Home has SPK 2. Windows doesn't allow you to upgrade to XP Professional SPK 1 it needs to be SPK 2.

OK the next step would be to somehow upgrade the XP Pro SPK 1 to XP Pro SPK 2. I found a way to do this using slipstream, at least that's what I thought. I tried several times to get this working, but every time it crashed the OS and I had to do a complete re-install of XP Home. So I finally gave up on the upgrade and I have done without the extra facilities that the Pro version provided.

To be honest the only thing I missed was the ISS. Which brings me back to the reason why I didn't want to pay for another upgrade, when I already have bought one when all I need is IIS.

So ... back to going about installing the IIS.

I discovered that this was possible with a few tweaks of the system.

I can't claim any of these methods of my own, but thought I would share them with you here. I did have to overcome a slight problem which I will cover shortly.

The crux of the installation is that you will need Windows 2000 to get IIS off.

change the sysoc.inf file located at C:\Windows\Inf\sysoc.inf

and change the iis entry from

iis=iis.dll,OcEntry,iis.inf,hide,7

to this

iis=iis2.dll,OcEntry,iis2.inf,,7

copy the iis.dl_ and iis.in_ from the Win 2000 CD and expand it to a temp file

Copy the iis.dll and iis.inf files to

c:\windows\System32\Setup and c:\windows\inf respectfully

Goto Add and remove programs and you should now see the option to add IIS under the windows components

You will need to change the default user name in Directory Security in IIS for you Default web site from IUSR_NAME so that it uses the computer name as well so it will say YOURCOMPUTERNAME\IUSR_NAME

As mentioned though I did have a few problems after get it installed. I set up the permission and ran some test .htm pages, and they all worked fine. However I couldn't run .asp page. So I tried following the suggestions on Brooks Younce pages.

How to Fix it! (if nothing else can!)Open "Control Panel" and then "Administrative Tools" then Open "Services"... Locate the "Distributed Transaction Coordinator" make sure the process is "Started" and "Automatic" (If its not, open a command line and type "msdtc -install", then try and start the service) Open a command line and type the following... cd %windir%\system32\inetsrv rundll32 wamreg.dll, CreateIISPackage (NOTE: "CreateIISPackage" must be typed exactly; it is case-sensitive.) regsvr32 asptxn.dll (wait for a dialog box to notify you asptxn has registered correctly) IISRESTART Open "Control Panel" then "Component Services"... You should see all three IIS COM+ applications that have been recreated

About Me

A lot of things have happend over the years, the biggest change is that I discovered that I have Cancer - Multiple Myeloma. I have created a blog to keep everyone informed of how I am doing. I find it a good way to keep occupied and take my mind off things as well.

I've changed my career so that I can manage my treatment as well as still earn some pennies in the process. I started a Photography business, please visit my web site at www.seantiernan.co.uk to see examples of my work. If your interested in photography or would like to have a go at modelling, please get in touch as I'm always looking for willing models to work with and build up both of our portfolios.

I also do commission work if you would like a particular shot for your living room wall, such as a specific type of flower in a certain colour to match your decor, then let me know and we can arrange something.

I'm supported by my lovely wife Charito (Maria) who is Peruvian and I couldn't do without her loving support and care that she provides on a daily basis.

I've seen this on other profiles and thought the following was a good idea.

Circles that I am interested in:

Main ones..

- Cancer related- Photography- Andoid and Tech related- Anonymous (non hacking non violent)- ArtwalkTV Community (so if you think I have added you randomly and you are part of this community, then this is where I have got your interest from)

If the circle you would like to put me in isn't here, then add me anyway. I do like to know your interests though, otherwise you will just go in my 'People I am following' this is for people who are too lazy to having got around to putting anything on their profile. I have loads of different circles but the main ones are are above.