Solved

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

Posted on 2014-10-14
4
468 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…

628 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