RuMoR
RuMoR

Reputation: 835

The Button ID does not get set to the Text of the Text Box

I am creating a text box tb and a button b, and I am trying to set the ID of the button to the text of the Text Box, however, the ID is set to empty string, and not to the string that is entered in the text box. Need help! Thank you.

    Button b = new Button();
    b.Text = "Comment";

    TextBox tb = new TextBox();
    String x = pno.ToString();
    b.ID = x + " " + tb.Text.ToString();
    form1.Controls.Add(tb);
    form1.Controls.Add(b);

    b.Click += new EventHandler(Button1_Click);

Upvotes: 0

Views: 72

Answers (1)

Chamika Sandamal
Chamika Sandamal

Reputation: 24302

tb is a new text box and it doesn't have any text. and don't put spaces in the ID field.

Upvotes: 1

Related Questions