Followers

Friday, 18 January 2013

asp.net Label: how to use

Label.aspx


  1. <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Label.aspx.cs" Inherits="Label" %>  
  2.   
  3. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">  
  4.   
  5. <html xmlns="http://www.w3.org/1999/xhtml">  
  6. <head runat="server">  
  7.     <title>asp.net Label: how to use</title>  
  8. </head>  
  9. <body>  
  10.     <form id="form1" runat="server">  
  11.     <div>  
  12.         <h2 style="color:Teal">Label</h2>  
  13.         <asp:Label   
  14.              ID="Label1"   
  15.              runat="server"  
  16.              Font-Size="Medium"  
  17.              Font-Italic="true"  
  18.              ForeColor="Tomato"  
  19.             >  
  20.         </asp:Label>  
  21.         <br /><br />  
  22.         <asp:Label  
  23.              ID="Label2"  
  24.              runat="server"  
  25.              ForeColor="Green"  
  26.              AssociatedControlID="TextBox1"  
  27.              AccessKey="C"  
  28.              >  
  29.              <u>C</u>ity  
  30.         </asp:Label>  
  31.         <asp:TextBox   
  32.             ID="TextBox1"   
  33.             runat="server"  
  34.             BackColor="Green"  
  35.             ForeColor="White"  
  36.             >  
  37.         </asp:TextBox>  
  38.         <br />  
  39.         <asp:Label  
  40.              ID="Label3"   
  41.              runat="server"   
  42.              >  
  43.              <u>Z</u>ip  
  44.         </asp:Label>  
  45.         <asp:TextBox  
  46.              ID="TextBox2"   
  47.              runat="server"  
  48.              BackColor="Green"  
  49.              ForeColor="White"  
  50.              >  
  51.         </asp:TextBox>  
  52.         <br />  
  53.         <asp:Button ID="Button1" runat="server" Text="Submit" OnClick="Button1_Click" />  
  54.     </div>  
  55.     </form>  
  56. </body>  
  57. </html>  

Label.aspx.cs


  1. using System;  
  2. using System.Collections;  
  3. using System.Configuration;  
  4. using System.Data;  
  5. using System.Linq;  
  6. using System.Web;  
  7. using System.Web.Security;  
  8. using System.Web.UI;  
  9. using System.Web.UI.HtmlControls;  
  10. using System.Web.UI.WebControls;  
  11. using System.Web.UI.WebControls.WebParts;  
  12. using System.Xml.Linq;  
  13.   
  14. public partial class Label : System.Web.UI.Page  
  15. {  
  16.     protected void Page_Load(object sender, EventArgs e)  
  17.     {  
  18.         if(!this.IsPostBack)  
  19.         {  
  20.             Label3.AssociatedControlID = "TextBox2";  
  21.             Label3.AccessKey = "Z";  
  22.             Label3.ForeColor = System.Drawing.Color.Green;  
  23.             Button1.Font.Bold = true;  
  24.             Button1.ForeColor = System.Drawing.Color.Green;  
  25.         }  
  26.     }  
  27.   
  28.     protected void Button1_Click(object sender, EventArgs e) {  
  29.         Label1.Text = "City: " + TextBox1.Text.ToString();  
  30.         Label1.Text += "<br />Zip: " + TextBox2.Text.ToString();  
  31.     }  
  32. }  






No comments:

Post a Comment