0
 private void txtenable (Boolean txtenable)
 {
     if(txtenable== false)
     {
         txtname.Enabled = false;
         txtTel.Enabled = false;
         txtmobile.Enabled = false;
         txtAdress.Enabled = false;
      }
      else
      {
           txtname.Enabled = true;
          txtTel.Enabled = true;
          txtmobile.Enabled = true;
          txtAdress.Enabled = true;
      }

 }

I want use this class but i can not call textboxes. How can call textbox in class?

7
  • You have given only method here. Please provide whole class. Also if possible, mention exact requirements what you are looking for? Commented Oct 11, 2016 at 13:27
  • i want create a class like up class Commented Oct 11, 2016 at 13:30
  • but in class how can call textbox Commented Oct 11, 2016 at 13:30
  • i write this code in notepad just notepad no in asp.net ....... ok? Commented Oct 11, 2016 at 13:31
  • Well in one line I can say, when you create object of that class, call this method. And while calling method pass your textbox as a reference. That way you can access your textbox. Commented Oct 11, 2016 at 13:33

1 Answer 1

2

First you need to be able to accept the TextBox objects within the class, then you can manipulate them how you see fit. I haven't actually tried this, but this is how I would go about setting it up.

public class YourClass
{
TextBox txtName; 
TextBox txtTel;
TextBox txtMobile;
TextBox txtAddress;
private void txtenable (Boolean txtenable, TextBox txtName, TextBox txtTel, TextBox txtMobile, TextBox txtAddress)
 {
 if(txtenable== false)
 {
     txtName.Enabled = false;
     txtTel.Enabled = false;
     txtMobile.Enabled = false;
     txtAddress.Enabled = false;
  }
  else
  {
      txtName.Enabled = true;
      txtTel.Enabled = true;
      txtMobile.Enabled = true;
      txtAddress.Enabled = true;
  }

}

In order for you to access the textboxes from within your class you will need to pass them such as:

public class OtherClassContainingTextBoxes
{
private void SomeEvent(object sender, EventArgs e){
txtenable(true, txtName, txtTel, txtMobile, txtAddress);
}

However, based on the example provided, I am unsure why you wouldn't do this in a method within the class you have your textboxes.

You could do something on pageload:

 protected void Page_Load(object sender, EventArgs e)
 {
    if (Session["enable"] == false){
       txtenable(false);
    }else{
      txtenable(true);
    }
 } 
private void txtenable (Boolean txtenable)
 {
     if(txtenable== false)
 {
         txtName.Enabled = false;
         txtTel.Enabled = false;
         txtMobile.Enabled = false;
         txtAddress.Enabled = false;
}
     else
     {
         txtName.Enabled = true;
         txtTel.Enabled = true;
         txtMobile.Enabled = true;
         txtAddress.Enabled = true;
      }

 }
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.