Please read this if you're just starting ASP.NET:
Hello World!
Last time, I showed you an event handler for on Page Load, well now I'm going to show you how to do soemthing for on button click!
Get your aspx started:
Code:
<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>Buttons!</title>
</head>
<body>
<form runat="server">
</form>
</body>
</html>
Ok Now let's set up a textbox, label and button:
Code:
<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>Buttons!</title>
</head>
<body>
<form runat="server">
<asp:TextBox id="text1" runat="server" />
<asp:Button id="button1" onclick="calculate_Click" runat="server" />
<asp:Label id="label1" runat="server" />
</form>
</body>
</html>
Notice the "onclick="", this is going to be a key feature here, it will be the name of the method we are about to put in between the head tags.
Code:
<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>Buttons!</title>
<script runat="server">
void calculate_Click (object sender, EventArgs e)
{
label1.Text = "Hello, "+text1.Text+".";
}
</script>
</head>
<body>
<form id="Form1" runat="server">
Name: <asp:TextBox id="text1" runat="server" />
<asp:Button id="button1" text="Enter" onclick="calculate_Click" runat="server" />
<br />
<span style="font-size: 12px; font-family:verdana;"><asp:Label id="label1" runat="server" /></span>
</form>
</body>
</html>
There, we took the text from the textbox, and put it in the label.
Well there's buttons from the basics for you!