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; 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; 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:
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.
Jump to Post— kvprajapati 1,826Use 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];
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]; We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.