Advertisement

12.28.2007 at 09:57AM PST, ID: 23047612
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

8.2

Show a different image for disabled ImageButton

Asked by Russ_Suter in Microsoft Visual C#.Net, C# Programming Language, Visual Studio

Tags: , ,

I found a very nice sample online of how to enhance the ImageButton control with rollover effects (see attached code snippet) and it works very well for that. I now need to have the ImageButton control display a different image when it is disabled so the user can clearly see that it is disabled. I've tried the following:

        protected override void RenderContents(HtmlTextWriter writer)
        {
            if (this.Enabled == false)
            {
                Image disabledImage = new Image();
                disabledImage.ImageUrl = this.DisabledImageUrl;
            }
            else
            {
                base.RenderContents(writer);
            }
        }

(I added a DisabledImageUrl property to the class)

This does render the disabled image but it renders it right next to the regular image rather than in place of it. How can I modify this control so when the control is disabled it displays the image specified in the DisabledImageUrl property rather than the ImageUrl property?Start Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
namespace CustomControls
{
    [DefaultProperty("Text")]
    [ToolboxData("<{0}:RolloverButton runat=server></{0}:RolloverButton>")]
    public class RolloverButton : ImageButton
    {
        [Bindable(true)]
        [Category("Appearance")]
        [DefaultValue("")]
        [Localizable(true)]
        public string RolloverImageUrl
        {
            get
            {
                if (ViewState["RolloverImageUrl"] == null)
                {
                    return string.Empty;
                }
                else
                {
                    return ViewState["RolloverImageUrl"].ToString();
                }
            }
            set
            {
                ViewState["RolloverImageUrl"] = value;
            }
        }
 
        protected override void AddAttributesToRender(HtmlTextWriter writer)
        {
            writer.AddAttribute("onmouseover", "this.src='" + base.ResolveClientUrl(RolloverImageUrl) + "'");
            writer.AddAttribute("onmouseout", "this.src='" + base.ResolveClientUrl(ImageUrl) + "'");
            base.AddAttributesToRender(writer);
        }
    }
}
[+][-]12.28.2007 at 11:57AM PST, ID: 20544615

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: Microsoft Visual C#.Net, C# Programming Language, Visual Studio
Tags: disabled, image, imagebutton
Sign Up Now!
Solution Provided By: GreenGhost
Participating Experts: 1
Solution Grade: A
 
 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628