Solved

ASP.NET Public Property - Can't get value from User Control

Posted on 2014-10-14
4
464 Views
Last Modified: 2014-10-19
I am working with a user control that is used as a selection criteria.  I need to have a checkbox depending on if a certain criteria is selected.  I have this working.  On the main form, I need to validate so I thought I would use public properties.  When checking the properties they values are false even though I set them to true.

//USER CONTROL CODE
 private short GetSelection()
        {
            short iSelection = 0;
            int iPlanc = 0;

            if (ViewState["Planc"] != null)
            {
                iPlanc = Convert.ToInt32(ViewState["Planc"]);
            }

            RowSelectorColumn myColumn = RowSelectorColumn.FindColumn(dgPlan);
            if (myColumn.SelectedIndexes.Length > 0) 
                iSelection = Convert.ToInt16(dgBenefit.DataKeys[myColumn.SelectedIndexes[0]]);

            if (iSelection == iPlanc)
            {
                this.pnlValidate.Visible = true;
                bValidate = true;  //Have been declare private above
                bValidChecked = false;  //Have been declare private above
            }
            else
            {
                this.pnlValidate.Visible = false;
                bValidate = false;  //Have been declare private above
                bValidChecked = false;  //Have been declare private above
            }

            return iSelection;
        }

        protected void chkValid_Checked(object sender, EventArgs e)
        {
            if (this.chkValid.Checked)
                bValidChecked = true;
            else
                bValidChecked = false;
        }

        public bool ValidChecked
        {
            get
            {
                return bValidChecked;
            }
        }

        public bool Validate
        {
            get
            {
                return bValidate;
            }
        }

Open in new window


//CODE IN MAIN FORM THAT INHERITS THE USER CONTROL
    protected void lnkNext_Click(object sender, System.EventArgs e)
    {
        try
        {
            lblMessage.Text = string.Empty;
            
             //User Control - Always returns False
            if (SelectionGrid1.Validate == true)
            {
                if (SelectionGrid1.ValidChecked == false)
                {
                    lblMessage.Text = "You must blah blah blah to continue.";
                    return;
                }
            }
        }
        catch (ApplicationException ex)
        {
            lblMessage.Text = ex.Message;
            return;
        }
    }

Open in new window

0
Comment
Question by:CipherIS
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 34

Expert Comment

by:it_saige
ID: 40380876
It is just as easy to just have your ValidChecked property return the state of the checkbox:
public bool ValidChecked
{
	get { return this.chkValid.Checked };
}

Open in new window


-saige-
0
 
LVL 1

Accepted Solution

by:
CipherIS earned 0 total points
ID: 40380895
The problem is that the checkbox MUST be checked only if ONE out of "n" is checked.  That value of one is stored in the web.config file.  When it matches then I need to check the value of the check box.

if (iSelection == iPlanc) is comparing the Selection to the value stored in the web.config (iPlanc - which I stored in ViewState)

I solved it by storing the variables in Viewstate this way it retains its value.  

The properties work as designed now.
0
 
LVL 34

Expert Comment

by:it_saige
ID: 40380911
Gotcha.  Glad you got it resolved.

-saige-
0
 
LVL 1

Author Closing Comment

by:CipherIS
ID: 40389818
Stored values in Viewstate and it resolved the issue.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

738 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question