Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. How to get TextBox value from one class to another

How to get TextBox value from one class to another

Scheduled Pinned Locked Moved ASP.NET
tutorial
6 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Sr Frank
    wrote on last edited by
    #1

    public partial class Form2 : Form { public Form2() { InitializeComponent(); } private void Form2_Load(object sender, EventArgs e) { } } public class test { string strID; public string hello() { strID= this.txtTextBox1.Text; //here i am confused with my basic concept (can i assign value to strID from TextBox and if yes then how to get TextBox Value from form2 because I am making a new class here) return strID; } } }

    A E T J 4 Replies Last reply
    0
    • S Sr Frank

      public partial class Form2 : Form { public Form2() { InitializeComponent(); } private void Form2_Load(object sender, EventArgs e) { } } public class test { string strID; public string hello() { strID= this.txtTextBox1.Text; //here i am confused with my basic concept (can i assign value to strID from TextBox and if yes then how to get TextBox Value from form2 because I am making a new class here) return strID; } } }

      A Offline
      A Offline
      Abhijit Jana
      wrote on last edited by
      #2

      How this is related with ASP.NET ? This is your Windows Application ..

      Cheers ! Abhijit Web Site : abhijitjana.net Don't forget to click "Good Answer" on the post(s) that helped you.

      1 Reply Last reply
      0
      • S Sr Frank

        public partial class Form2 : Form { public Form2() { InitializeComponent(); } private void Form2_Load(object sender, EventArgs e) { } } public class test { string strID; public string hello() { strID= this.txtTextBox1.Text; //here i am confused with my basic concept (can i assign value to strID from TextBox and if yes then how to get TextBox Value from form2 because I am making a new class here) return strID; } } }

        E Offline
        E Offline
        Enobong Adahada
        wrote on last edited by
        #3

        Create a static class with global var, in you form 2, asign the value of text box to the var, you can use the value anywhere you want by refrencing the class and the varibale. hope this helps.

        1 Reply Last reply
        0
        • S Sr Frank

          public partial class Form2 : Form { public Form2() { InitializeComponent(); } private void Form2_Load(object sender, EventArgs e) { } } public class test { string strID; public string hello() { strID= this.txtTextBox1.Text; //here i am confused with my basic concept (can i assign value to strID from TextBox and if yes then how to get TextBox Value from form2 because I am making a new class here) return strID; } } }

          T Offline
          T Offline
          T M Gray
          wrote on last edited by
          #4

          What do you intend to do with the test class? (choose better names like MyTestClass so you don't accidentally use reserved words) You should create a public property in your MyTestClass for the strID. (Tip: type prop and hit tab twice). Create an instance of your MyTestClass in the form load of Form2 and then you can set the TextChanged event of txtTextBox1 to set the value of that property. You might want to do some reading on object oriented programming. From what you have written it looks like you are used to procedural programming. Try this one C# Tutorial - An Object Oriented Approach to Programming[^]

          1 Reply Last reply
          0
          • S Sr Frank

            public partial class Form2 : Form { public Form2() { InitializeComponent(); } private void Form2_Load(object sender, EventArgs e) { } } public class test { string strID; public string hello() { strID= this.txtTextBox1.Text; //here i am confused with my basic concept (can i assign value to strID from TextBox and if yes then how to get TextBox Value from form2 because I am making a new class here) return strID; } } }

            J Offline
            J Offline
            jaypatel512
            wrote on last edited by
            #5

            public partial class Form2 : Form { public Form2() { InitializeComponent(); } private void Form2_Load(object sender, EventArgs e) { test t1 = new test(); //Create an instance of test class. t1.hello(textbox1.text); } } public class test { string strID; public string hello(string message) { strID= message; //here i am confused with my basic concept (can i assign value to strID from TextBox and if yes then how to get TextBox Value from form2 because I am making a new class here) return strID; } } }

            jaypatel512

            E 1 Reply Last reply
            0
            • J jaypatel512

              public partial class Form2 : Form { public Form2() { InitializeComponent(); } private void Form2_Load(object sender, EventArgs e) { test t1 = new test(); //Create an instance of test class. t1.hello(textbox1.text); } } public class test { string strID; public string hello(string message) { strID= message; //here i am confused with my basic concept (can i assign value to strID from TextBox and if yes then how to get TextBox Value from form2 because I am making a new class here) return strID; } } }

              jaypatel512

              E Offline
              E Offline
              Enobong Adahada
              wrote on last edited by
              #6

              the question is not clear what exacly do u want to do, do you have two forms, or are u requesting the valu from the same form. you can use a command button and put your code in the click event of the button. hope this helps.

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups