Archive for February, 2008

AJAX PopupControlExtender and Dynamic Controls

28 February, 2008 3 comments

I was attempting to use the PopupControl Extender the other day, to create myself a web user control for colour selection.

Here is what I ended up creating..

Figure 1

The problem I had was that the colour palette panel is being created dynamically. In this example it is a 25×16 matrix made up of 375 dynamically created link buttons with their backcolour set to the colour from the palette. (Note: Used a link button due to postback.Asynch javascript errors that occur with PopupControl Extender in a modal dialog box as documented elsewhere on the web).

When a user clicked on one of the link buttons it performed a postback, problem was it was doing a full postback and closing the popup window.

Solution: When creating your controls dynamically to exist in your panel to be displayed by the popup extender you need to register them with the UpdatePanel triggers collection like so:

LinkButton btnColour = new LinkButton();
... setup you link button
btnColour.ID = colurHexCode; // colurHexCode string variable containing the current colour I am setting as the backgroud
AsyncPostBackTrigger trigger = new AsyncPostBackTrigger();
trigger.ControlID = btnColour.ID;

This forces the dynamic control to be included in the update panel and when clicked only performs a partial update panel postback.


Categories: AJAX, ASP .Net

Setting the Default Button on Pressing Enter

27 February, 2008 1 comment

On a page with a single text box and a button, place your cursor in the text box and press enter. The page will submit back to itself but not hit the click event behind your submit button as expected.

See here: for a full discussion of the issue.

The fix for this simple problem is to add another text box like so:

<asp:textbox runat="server"  
style="visibility:hidden; display:none;">

This however only fixes the page posting to itself, we now need to get the page to fire the default button’s click event.My problem is further complicated by these facts:

1. The page is using a master page with the main content area containing the text box and a footer content area containing the button.

2. The button is not an  <asp:button…  but a custom button control that uses an asp:hyperlink control.

There is a DefaultButton property that can be set on the form. The caveat being when using master pages you must use the uniqueID of the control. So in my page onload event the following line of code needs to be added.

this.Page.Form.DefaultButton = btnOK.UniqueID;

This causes the btnOk “Click” event to be fired.


Categories: ASP .Net

Dynamically creating user controls in code behind

27 February, 2008 Leave a comment

If you have a user control that you wish to dynamically add to your page the following will not work;

UserControl control = new UserControl()

The problem is that the control has not been successfully created and all the internal controls that make up the user control, like text boxes etc, will be null.

The way to create the control is with the “LoadControl()” statement.

UserControl control = LoadControl("~/controls/UserControl.ascx") as UserControl;

and now it will work.

Categories: c#, Code Tags: ,

Bootstrap Manifest Generator – How To Setup Custom Pre-Requisites

27 February, 2008 12 comments

Edit March 2011
I have just done a newer version of this page, with pictures, you may want to check it out here
BootStrap Manifest Generator (2008) – How To Guide v2

Original Post Feb 2008 Continued…

Recently I was attempting to create a deployment package that has customised pre-requisites i.e I wanted my installer to detect if AJAX Extensions 1.0 was installed and if not ask the user to install it.

I found this link talking about how to do it..

Which lead me to download the Bootstapper Manifest generator from

I was a bit lost with what to do so hopefully this will save you the pain I went though.

(Note: the BMG is really buggy. Most of the system checks don’t work, and once you add a file system check and save your project you can no longer open your bootstrap project. But given it is free it’s better than attempting to write the XML by hand)

As an example to create a pre-requisite for AJAX follow these steps:
  1. Run the BMG tool.
  2. Create a new Package Manifest. Give it a name, AJAX
  3. Add a file, choose the AJAX Extension installer .msi.
  4. Give it a name, this will be the name that appears in your installer so make it something nice like “Microsoft ASP .Net 2.0 AJAX Extensions 1.0”
  5. Build it.
Now if it builds have a look at the location that it is written to, it is a visual studio directory, so I thought to myself it must integrate with VS2005.
So open your Setup Project in visual studio, (in my case, a Web Setup Project). Right Click — Properties on the solution. There in the bottom right is the pre-requisite button.
Click on it and you should now see AJAX as an option.
Traps for young players
1. Copy paste
Inside the BGM copy and paste does not appear to work. The trick, is right click in the field and choose paste.
2. Download from web Option
If you want to download from the web enter the url for the .exe. I setup my own publically available spot to allow downloading these pre-requesites (rather than relying on the microsoft download site), as they migth change things. So I have a known static location to go download the AJAX Extensions msi.
3. System Checks
You should include a check to see whether AJAX is already installed.
In your manifest click on the file you added, and go to the “System Checks” tab. I found that most of the system checks did not work properly.
I found the one that did work was a file check, so I added a file check for System.Web.Extensions.dll in the default location
  • Add a File check. Set the file name to System.Web.Extensions.dll, turn off the search, and enter the default path to the ASP Net folder.
  • Switch to the “Install Conditions” tab and add a line that says:
    • Type – By Pass If
    • Property – AJAX (or the name you gave your system check)
    • Comparison  – Exists

Cheers and Goodluck

Categories: AJAX, Code Tags: ,