Using ASP.NET Server Controls

Anatomy of ASP.NET Page

I have constructed a very simple ASP.NET page to illustrate how very simple it is.


<% @Page language="C#"%>
<html>
<script language="C#" runat=server>   
 
private void btnclick_click(object sender, EventArgs e)
  {
    if (cmbcolor.SelectedItem.Text == "red")
      lblcolor.BackColor = System.Drawing.Color.Red;
    if (cmbcolor.SelectedItem.Text == "blue")
      lblcolor.BackColor = System.Drawing.Color.Blue;
    if (cmbcolor.SelectedItem.Text == "yellow")
      lblcolor.BackColor = System.Drawing.Color.Yellow;
    if (cmbcolor.SelectedItem.Text == "green")
      lblcolor.BackColor = System.Drawing.Color.Green;
  }        
</script>

<body>
<form action="intro.aspx" method="post" runat="server">     
<asp:Label runat="server" id="lblcolor" Text="COLOR CHANGE DEMO"/>
<br><br>
<asp:DropDownList id=cmbcolor runat="server">
   <asp:ListItem Value="red">red</asp:ListItem>
   <asp:ListItem Value="blue">blue</asp:ListItem>
   <asp:ListItem Value="yellow">yellow</asp:ListItem>
   <asp:ListItem Value="green">green</asp:ListItem>
</asp:DropDownList>
<br><br>

<asp:Button Text="Click Here" id="btnClick"
   onClick="btnclick_click" Runat=server />

<br>
</form>
</body>
</html>

One new piece of code is the new <%@PAGE %> directive. It controls a lot of functionality for your page. One of the most useful is the ASPCOMPAT attribute, - this Boolean value determines if the page is backward compatible. You must set this attribute to true if you are calling legacy ActiveX DLL's.

You might also like...

Comments

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“God could create the world in six days because he didn't have to make it compatible with the previous version.”