sumgi sumgi -4 years ago 103
ASP.NET (C#) Question

Add multiple rows of text to a text box with different buttons c#

I have built an interface full of buttons (47) and each of them have an address. When you click the button, it's supposed to put the address in the text box. I can do this, but only with one address at a time. When I push a different button the previous address gets copied over by the new one.

The code behind the buttons are simple:

protected void btnYmca_Click(object sender, EventArgs e)
{
txtOut.Text = "Some address here\n";
}


All of these buttons are set up like this. There is nothing in these buttons to clear the text, but it does automatically when I click a different button. The text box is set to MultiLine.

Is there a way to make the text line stay in the text box when you hit one button, then add a new address on a line below it? I have a separate button to clear the text box when finished.

Answer Source

You need to add a + before the =. This will then append the value instead of overwriting it.

protected void btnYmca_Click(object sender, EventArgs e)
{
    txtOut.Text += "Some address here\n";
}
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download