[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

Question
[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

New to .NET 2.0 user controls - Need help with public properties

Asked by DJMikeAZ in Microsoft Visual C#.Net, Programming for ASP.NET, .NET Framework 2.x

Tags: imagebutton, programatically

I am building a custom "Yes/No" control for a survey application. The control has 2 labels (Yes/No) and two image buttons which display a graphical version of a checkbox. What I need is simple, when the user clicks on either the yes or no, the images change to reflect the new value of the control-- as in when 'Yes' is selected, the 'yes' image button url changes to the selected graphic and the 'no' image button changes to the unselected variation. Fortunately, I have that part working ok (although I'm sure there's a better way to do it). What I need help with is exposing a value property for the control so when a user selects yes or no, the value is modified accordingly. I need to programatically be able to set or get the value of the control and it will render as such. I tried doing it the way I thought would work however, the value does not persist on postback so it's always false. When I debug, clicking "Yes" set's  _value to true but when the page loads again, it's back to false. I will paste the control code and the codebehind I have now. Any help is very appreciated.

- Mike


=============== YESNOCONTROL.ASCX ========================

<asp:Table runat="server" ID="tblYesNo" CssClass="yesNoTable">
            <asp:TableRow CssClass="yesNoRow">
            <asp:TableCell CssClass="yesNoTableData">
                <asp:LinkButton ID="lnYes" OnClick="Yes_Click" CssClass="yesNoLink" ForeColor="Black" Font-Underline="false" runat="server">Yes</asp:LinkButton>
                <asp:ImageButton runat="server" OnClick="Yes_Click"  ID="imgYes" CssClass="yesNoImage" ImageUrl="~/Images/YesNo_default.jpg" Width="25" Height="20" />            
            </asp:TableCell>
            <asp:TableCell CssClass="yesNoTableData">
                    <asp:LinkButton ID="lnNo" OnClick="No_Click"  CssClass="yesNoLink" ForeColor="Black" Font-Underline="false" runat="server">No</asp:LinkButton>
                    <asp:ImageButton runat="server" OnClick="No_Click"  ID="imgNo" CssClass="yesNoImage" ImageUrl="~/Images/YesNo_selected.jpg" Width="25" Height="20" />                        
                </asp:TableCell>
            </asp:TableRow>
        </asp:Table>




=============== YESNOCONTROL.ASCX.CS ========================

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.ComponentModel;

public partial class Modules_YesNoControl : System.Web.UI.UserControl
{
   
    private bool _value = false;

    protected void Page_Load(object sender, EventArgs e)
    {

    }

    [Bindable(true),Category("Behavior"),Description("Set the default value of this control"),DefaultValue(false),Localizable(true)]
    public bool Value
    {
        get
        {
            return _value;

        }
        set
        {
            _value = value;          
        }
    }
      

    protected void Yes_Click(object sender, EventArgs e)
    {
        _value = true;
        imgYes.ImageUrl = "~/Images/YesNo_selected.jpg";
        imgNo.ImageUrl = "~/Images/YesNo_default.jpg";
       
    }

    protected void No_Click(object sender, EventArgs e)
    {
        _value = false;
        imgYes.ImageUrl = "~/Images/YesNo_default.jpg";
        imgNo.ImageUrl = "~/Images/YesNo_selected.jpg";
    }

}
 
Related Solutions
Keywords: New to .NET 2.0 user controls - …
 
Loading Advertisement...
 
[+][-]04/20/07 12:42 AM, ID: 18944723Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04/20/07 08:23 AM, ID: 18947133Accepted Solution

View this solution now by starting your 30-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, Programming for ASP.NET, .NET Framework 2.x
Tags: imagebutton, programatically
Sign Up Now!
Solution Provided By: Edwin_C
Participating Experts: 2
Solution Grade: A
 
[+][-]04/20/07 08:29 AM, ID: 18947185Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]04/20/07 11:19 AM, ID: 18948481Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20091021-EE-VQP-81