how do i receive two separate inputs from the same text box?

here is what i have so far:

c1 = textBox1.Text;
textBox1.Clear();
c2 = textBox1.Text;

Dani AI

Generated

The simplest pattern is: capture the box contents when the user clicks the button, store that captured value in a place that lives long enough for your workflow, clear the box and prompt for the next entry. confirmed the inputs are entered one after the other; is correct to use the button click as the capture moment; and ’s idea to keep entries for later use is the right direction when you need more than a pair of values. Whether you implement this in a WinForms desktop app or an ASP.NET web app changes how you keep that stored state (form-level fields for desktop; client-side state, hidden fields, or server-side session/ViewState semantics for web pages).

Practical checklist:

  • On the button click, read and trim the textbox text and reject empties.
  • Save the value into a field, an index-tracked slot, or a collection depending on needs.
  • Update the UI so the user knows to enter the next value (label, placeholder, or message).
  • Clear the input and set focus back to it.
  • When two values are captured, proceed with processing and then reset the state.

Troubleshooting notes: avoid out-of-range errors when reading stored entries; if using a web page, prefer client-side capture or AJAX to reduce full postbacks; if the app must support many sequential entries, use a collection and defensive checks. These practices make the "same textbox, multiple entries" flow robust and user-friendly.

Recommended Answers

All 4 Replies

Are you entering both the values at the same time or one after the other?

one after the other. the user is supposed to enter a value, press a button, then enter the next value in the same text box.

On the click event of the button you can capture the data and clear it.
For eg.

c1 = Textbox1.text;
Textbox1.clear();

Use List<String> to hold one or more values.

List<string> data=new List<string>();
private void button1_Click(object sender, EventArgs e)
        {
             data.add(TextBox1.Text)
             TextBox1.Cler();
        }

Get value/text from data collection:

String c1=data[0];
String c2=data[1];
commented: Right! +8
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.