Results 1 to 2 of 2

Thread: C# Question, How do I assign the value of a textbox to a local variable?

  1. #1
    Join Date
    Dec 2008
    Posts
    2

    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();

    }

  2. #2
    Join Date
    May 2008
    Posts
    188

    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.

Similar Threads

  1. Assign a text file from hard disk into a VBA string variable
    By AbiCgail in forum Software Development
    Replies: 5
    Last Post: 15-07-2011, 10:49 AM
  2. Assign each line of a text file to a variable
    By hitman126 in forum Operating Systems
    Replies: 1
    Last Post: 22-01-2011, 07:42 AM
  3. Replies: 2
    Last Post: 20-08-2010, 01:23 AM
  4. Replies: 2
    Last Post: 28-08-2009, 07:51 PM
  5. Replies: 1
    Last Post: 25-09-2008, 02:23 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,721,088,281.83696 seconds with 17 queries