Cusotm Image button and themes

  • Thread starter Thread starter CK
  • Start date Start date
C

CK

Hello All,
I am trying to extend the default asp:ImageButton to include an image for an
enabled state and a second image for a disabled state. I currently did this
by extending the ImageButton class in a custom control, creating a property
for each of these images (EnabledImageUrl, DisabledImageUrl) and then
overrode the Enabled property to change base.ImageUrl respectively. I am
also trying to use Themes with this web site. The problem is (I can tell by
looking in the page source) that when the image urls are stored in the
custom control they are not being resolved to the actual path of the images
(they are "image\<picName>.gif" in the skin file). Also, when the ImageUrl
is set on the base class it is also not being resolved to the actual (theme)
path. I was wondering if there is something I have to do with my custom
control, some convenience method I can run to resolve these paths or if
there is a specific point in the ASP page lifecycle that I have to plug in
to in order for these paths to get resolved by default.
public class MultiImageButton : ImageButton
{
private string _enabledImageUrl;
private string _disabledImageUrl;
public bool Enabled
{
get { return base.Enabled; }
set{
base.Enabled = value;
base.ImageUrl = value ? _enabledImageUrl :
_disabledImageUrl;
}
}

public string EnabledImageUrl
{
get { return _enabledImageUrl; }
set{
_enabledImageUrl = value;
if (Enabled)
base.ImageUrl = Page._enabledImageUrl;
}
}

public string DisabledImageUrl
{
get
{
return _disabledImageUrl;
}
set
{
_disabledImageUrl = value;
if (!Enabled)
base.ImageUrl = _disabledImageUrl;
}
}
}
 
I did a rollover image that was inherited from the image class. To get the
client side url of the images (and be able to use the ~), which I am
assuming is your issue, use ResolveClientUrl in your RenderControl method
(or in a function you call to help build the HTML output).

return base.ResolveClientUrl(_swapImageUrl);


--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA
http://gregorybeamer.spaces.live.com/

*************************************************
Think Outside the Box!
*************************************************
 
Thanks for the reply. I did try that before and it didn't work, but it's
good to know what that method is used for. When I used it, the method
returned an absolute path for the website based on the location of the page
containing the control. My problem is that the theme information is located
at \\WebSite\App_Themes\MyTheme\ with the images for that theme located at
\\WebSite\App_Themes\MyTheme\Images and most of the pages of my site have a
path similar to \\WebSite\MyWebPage.aspx. All of the other skin information
for traditional asp controls contains properties like ImageUrl="images\mypic.gif"
and they work correctly. Using Reflector, I was able to determine that, at
some point, the page itself iterates through its controls and applies skin
information, which I'm assuming also includes adjusting the paths to any
skin information to absolute paths. For some reason, the paths on this
custom control and its parent are not being adjusted to include the skin
path (when I view the source of the page, the image src for the custom
control is still "images\mypic.gif" where all of the other paths have been
changed to "App_Themes\MyTheme\images\mypic.gif").


I'm thinking there has to be some type of attribute I am missing or some
type of method I need to implement to get this custom control to be included
when the page is adjusting the paths for the skin information

TIA
~CK
 
Back
Top