Link to home
Start Free TrialLog in
Avatar of amillyard
amillyardFlag for United Kingdom of Great Britain and Northern Ireland

asked on

"cannot convert from 'object' to 'string'"

Development platform : c# asp.net 2.x, iis 6

I am getting a compiler error as follows:

"cannot convert from 'object' to 'string'"

for the line:  return bool.Parse(ViewState["_isChecked"];

your time and efforts with this enquiry are much apprieated.

many thanks.
SOLUTION
Avatar of Mikkk
Mikkk

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of amillyard

ASKER

@Mikkk - as requested :

        public bool _isChecked
        {
            get
            {
                if (ViewState["_isChecked"] == null)
                {
                    return false;
                }
                else
                {
                    return bool.Parse(ViewState["_isChecked"]);
                }
            }
            set
            {
                ViewState["_isChecked"] = value;
            }
        }
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
@Mikkk,

ok, thanks.  have updated scripting, am geting the following compiling error message as follows:

'object' does not contain a definition for .value (blue underline for .value)
@Limbeck

thank you for your contribution also.

the :  return bool.Parse((string)ViewState["_isChecked"]);  is compiling ok -- am just checking function itself is doing what I am hoping it should be achieving...
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
@Mikkk - I had to add the " ", in order to compile -- am checking functionality to confirm the script is performing as expected.

return (ViewState["_isChecked"]=="true");
In the calling procedure - I am using :

        protected void Page_PreRender(object sender, EventArgs e)
        {
            ViewState["_isChecked"] = RadioButton_Role.Checked;
           
           if (ViewState["_isChecked"] )
           {
                RadioButton_Role.Checked = false;
                RadioButton_StaffMember.Checked = true;
           }
        }

i.e. to check the Radio Button checked status (historic user interation changes to button status) and reconfigure on a PreRender request.

the line :

if (ViewState["_isChecked"]) is not compiling -- a casting error.

what I am trying to check if the state is true or false ... what I am doing wrong here please?


__updated procedure______________________________

       public bool _isChecked
        {
            get
            {
                if (ViewState["_isChecked"] == null)
                {
                    return false;
                }
                else
                {
                    return (ViewState["_isChecked"] == "true");
                    //return bool.Parse((string)ViewState["_isChecked"]);
                }
            }
            set
            {
                ViewState["_isChecked"] = value;
            }
        }
SOLUTION
Avatar of p_davis
p_davis

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
@p_davis : worked 1st time -- thank you
@Mikkk, @Limbeck -- thank you both for your contributions :-)
Avatar of p_davis
p_davis

your welcome
glad to be of help :)

Ed.