Question : C# code for writing up a class file....

1. Class file: HTMLControls.cs
   ****************
using System;
using System.Collections.Generic;
using System.Text;

namespace Example
{
    public class HTMLControls
    {
        //HTML Button objects repository
        internal string _btn_Login = "_ctl6_lbtnLogin";
        internal string _btn_Logout = "//a[@id='logout']/span";

        //HTML Text object repository
        internal string _txt_UserName = "_ctl6_tbUsername";
        internal string _txt_Password = "_ctl6_tbPassword";
    }
}

***************************************************************************************
***************************************************************************************

2. Class file: HTMLButton.cs
   ****************
using System;
using System.Collections.Generic;
using System.Text;

namespace Example
{
    public class HTMLButton : HTMLControls
    {
        public string btn_Login
        {   get{return _btn_Login;}
        }

        public string btn_Logout
        {   get{return _btn_Logout;}
        }
    }
}

***************************************************************************************
***************************************************************************************

3. Class file: HTMLText.cs
   ****************
using System;
using System.Collections.Generic;
using System.Text;

namespace Example
{
    public class HTMLText : HTMLControls
    {
        public string txt_Username
        {
            get { return _txt_UserName; }
        }

        public string txt_Password
        {
            get { return _txt_Password; }
        }
    }
}

***************************************************************************************
***************************************************************************************

4. Now I want to design a single class file say "Pages" in which there will be different functions like
- LoginPage
- HomePage

"LoginPage" function should have logic to call different methods from HTMLButton and HTMLText class files.
"HomePage" function should have logic to call different methods from HTMLButton and HTMLText class files.

Once this class is designed then we have the below mentioned problem.

***************************************************************************************
***************************************************************************************
5. In the Main class file I should be able to refer to the string value with

Pages.LoginPage.btn_Login - which should return me a string value.
where,
Pages is a class name from section 4.
LoginPage is a function name from section 4.
btn_Login is a function name from section 2.

Kindly provide some solution in c# code on how can we write the section 4 class file such that we can call the appropriate value in the main class file?

regards,
Sanjay

 

 

 

 

 

 

Answer : C# code for writing up a class file....

On a hunch is sounds like you should be using Master pages.  Master pages act like templates with prebuilt controls already defined.  You could have a 'Login' master page and a 'Home' master page and when you create a page include the master page with the behavior and layout you need predefined.

This question sounds like you are trying to reinvent the wheel.
Random Solutions  
 
programming4us programming4us