Solved

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

Posted on 2014-10-14
4
448 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
  • 2
  • 2
4 Comments
 
LVL 32

Expert Comment

by:it_saige
Comment Utility
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
Comment Utility
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 32

Expert Comment

by:it_saige
Comment Utility
Gotcha.  Glad you got it resolved.

-saige-
0
 
LVL 1

Author Closing Comment

by:CipherIS
Comment Utility
Stored values in Viewstate and it resolved the issue.
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Suggested Solutions

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

763 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now