Home > AJAX, ASP .Net > AJAX PopupControlExtender and Dynamic Controls

AJAX PopupControlExtender and Dynamic Controls

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;
UpdatePanel1.Triggers.Add(trigger);

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

Sweet

Advertisements
Categories: AJAX, ASP .Net
  1. rem
    16 November, 2008 at 8:18 am

    Helpfull blog…

  2. 19 February, 2010 at 9:43 am

    I like to use AJAX. Thanks for the info.

  3. 7 July, 2011 at 12:50 pm

    Thank’s. I was beating my head against a wall trying to resolve this same thing.

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: