C# Question, How do I assign the value of a textbox to a local variable?
I writing a small web application for my company using aspx and C#. I am new to visual C# and am still learning.
I have two text boxes, "textBox1" is for entering a note for a file, this creates a .txt file. The other textbox(TextBox2) is to enter the file number so it can name the text file accordingly. I need to assign the value of TextBox2 to a variable(filename) so that it will name the text file dynamically. I may be going about this the wrong way. Any help would be greatly appropriated. Below is the code that writes the next file.
public void Button1_Click1(object sender, EventArgs e)
{
string filename;
filename = ?????????;
StreamWriter sw = new StreamWriter(filename);
sw.WriteLine(textBox1.Text);
sw.Close();
}
Re: C# Question, How do I assign the value of a textbox to a local variable?
Why don't you use something like:
Code:
public void Button1_Click1(object sender, EventArgs e)
{
string filename;
filename = textBox1.Text;
......
}
It will directly assign the value of your textbox to the variable.