views:

174

answers:

2

I found a control adapter for asp.net wizard control. I would like to use it on my website. But I already have a few pages that use wizard controls. I don't want those pages to use the new adapter. Is it possible?

+1  A: 

I haven't worked directly with the adapters but from reading the documentation, it looks like you might be able to subclass the wizard control into your own version - say "AdaptedWizard". You wouldn't have to make any overrides to the base code, unless it would help some other issue you're having.

From there, it appears you could modify the .browser file to reference your AdaptedWizard class instead of the default Wizard class. Then all the new wizards on your site would be classed from AdaptedWizard instead of Wizard.

Good luck!

Nate

Nathan Southerland
Yep, this works a treat - i've done it for a few items like that.
Zhaph - Ben Duguid
A: 

If you have access to the source code you could edit the control adapter to first check that a custom attribute exists and has the correct value before adapting the control's output. You should remove the custom attribute before you render otherwise it will be rendered as html.

I've used this on many control adapters and it works fine and gives you an indication inline what controls are adapted. It also removes the need to create extended classes.

The code below is how I determine if the control should be adapted.

public class TestAdapter : WebControlAdapter
{
    bool _adapt = false;

    protected override void OnInit(EventArgs e)
    {
     Check();
     base.OnInit(e);
    }


    void Check()
    {
     // search for custom attribute
     const string att = "adapt";
     string value = this.Control.Attributes[att];

     if (string.IsNullOrEmpty(value))
     {
      return;
     }

     if (!bool.TryParse(value, out _adapt))
     {
      throw new InvalidOperationException("adapt attribute has invalid value : " + value);
     }

     this.Control.Attributes.Remove(att);
    }
}
Damien McGivern