Unable to read or fetch values set in Class Properties in C# .Net

Last Reply on May 08, 2013 03:30 AM By RkHirpara

Posted on May 08, 2013 02:19 AM

Hi ,


I have some properties in my base page like this.

It reading empty. Which means, I think property not beeing set.

  public string AccountNo { get; set; }
        public string IndTitle { get; set; }
        public string FirstName { get; set; }
        public string MiddleName { get; set; }
        public string LastName { get; set; }
        public string DateOfBirth { get; set; }
        public string Gender { get; set; }


I am trying to set these properties in some other page like this

BasePage Bobj = new BasePage();
   Bobj.AccountNo = txtAccount.Text;
            Bobj.IndTitle = ddlTitle.SelectedValue;
            Bobj.FirstName = txtFirstName.Text;
            Bobj.LastName = txtLastName.Text;



again i am trying to read these properties in some another page like this.

        BasePage Obj = new BasePage();
 ltAccount.Text = Obj.AccountNo;
            ltddlTitle.Text = Obj.CAState;
            ltFirstName.Text = Obj.FirstName;
            ltMiddleName.Text = Obj.MiddleName;
            ltLastName.Text = Obj.LastName;

 

You are viewing reply posted by: RkHirpara on May 08, 2013 03:30 AM.
Posted on May 08, 2013 03:30 AM

Hi Mahesh,

Its right, It should work only such a way.

Its as per Object Oriented Concept. As you cannot use one objects property by any other object. Proerty set by Bobj can be accessible only by Bobj, no one else.(Even not by other object having same name). How ever do the following thing.

Declare that property as static and use it without object. I am giving you example for one of the properties than you have to implement this to all other in exacly same manner.

1) Declare as static.

public static string AccountNo { get; set; }

2) Assign value(as its static you cannot use object but the class name directly as follow)

BasePage.AccountNo = txtAccount.Text;

3) User its value directly as

 ltAccount.Text = BasePage.AccountNo;

-- Please Read Object oriented concept to enjoy programming.

Thanks and Regards,

Rk_Hirpara.

I agree, here is the link: http://e-iceblue.com/free-api