ID: Label1
Text: "What kind of music do you like?"
Label 2:
ID: Label2
Text: Empty. Note that label 2 will be invisible if button is not clicked.
Button:
ID: Button1
Text: Submit
Text Box:
ID: TextBox1
Text: Empty
We can run the web form by right click any place on form and choose "View in Browser". We'll see only Label 1, Text Box and Button, Label 2 is still invisible.
Now we write some code to display text when Button is clicked. Choose Button, double click or use Properties window, choose Click action . VS or VWD autogenerate this code for us:
protected void Button1_Click(object sender, EventArgs e)
{
//We write code here
}
Run the form, enter color and click Button "Submit", Label 2 will be visible with text "You like: color".protected void Button1_Click(object sender, EventArgs e)
{
if (TextBox1.Text != "")
Label2.Text = "You like: " + TextBox1.Text;
else
Label2.Text = "You don't like any colors?!!";
}
Happy Coding! :)
Comments