Reputation: 2808
I am just a noob in C#, and I've got this question to ask you.
I have here a form that asks for login details. It has two textfields:
What I want is to get the strings entered in that textfields.
I am not yet familiar with the methods in C#..(in java, getString method is used). What could be the "equivalent" method here in C#?
Upvotes: 22
Views: 242904
Reputation: 37
to get value of textbox
string username = TextBox1.Text;
string password = TextBox2.Text;
to set value of textbox
TextBox1.Text = "my_username";
TextBox2.Text = "12345";
Upvotes: 0
Reputation:
if in string:
string yourVar = yourTextBoxname.Text;
if in numbers:
int yourVar = int.Parse(yourTextBoxname.Text);
Upvotes: 2
Reputation: 417
When using MVC, try using ViewBag. The best way to take input from textbox and displaying in View.
Upvotes: 4
Reputation: 48558
In C#, unlike java we do not have to use any method. TextBox property Text
is used to get or set its text.
Get
string username = txtusername.Text;
string password = txtpassword.Text;
Set
txtusername.Text = "my_username";
txtpassword.Text = "12345";
Upvotes: 46
Reputation: 547
I show you this with an example:
string userName= textBox1.text;
and then use it as you wish
Upvotes: 3
Reputation: 158289
The TextBox
control has a Text
property that you can use to get (or set) the text of the textbox.
Upvotes: 4