asp.net Label: how to use
Label.aspx
- <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Label.aspx.cs" Inherits="Label" %>
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head runat="server">
- <title>asp.net Label: how to use</title>
- </head>
- <body>
- <form id="form1" runat="server">
- <div>
- <h2 style="color:Teal">Label</h2>
- <asp:Label
- ID="Label1"
- runat="server"
- Font-Size="Medium"
- Font-Italic="true"
- ForeColor="Tomato"
- >
- </asp:Label>
- <br /><br />
- <asp:Label
- ID="Label2"
- runat="server"
- ForeColor="Green"
- AssociatedControlID="TextBox1"
- AccessKey="C"
- >
- <u>C</u>ity
- </asp:Label>
- <asp:TextBox
- ID="TextBox1"
- runat="server"
- BackColor="Green"
- ForeColor="White"
- >
- </asp:TextBox>
- <br />
- <asp:Label
- ID="Label3"
- runat="server"
- >
- <u>Z</u>ip
- </asp:Label>
- <asp:TextBox
- ID="TextBox2"
- runat="server"
- BackColor="Green"
- ForeColor="White"
- >
- </asp:TextBox>
- <br />
- <asp:Button ID="Button1" runat="server" Text="Submit" OnClick="Button1_Click" />
- </div>
- </form>
- </body>
- </html>
Label.aspx.cs
- using System;
- using System.Collections;
- using System.Configuration;
- using System.Data;
- using System.Linq;
- using System.Web;
- using System.Web.Security;
- using System.Web.UI;
- using System.Web.UI.HtmlControls;
- using System.Web.UI.WebControls;
- using System.Web.UI.WebControls.WebParts;
- using System.Xml.Linq;
- public partial class Label : System.Web.UI.Page
- {
- protected void Page_Load(object sender, EventArgs e)
- {
- if(!this.IsPostBack)
- {
- Label3.AssociatedControlID = "TextBox2";
- Label3.AccessKey = "Z";
- Label3.ForeColor = System.Drawing.Color.Green;
- Button1.Font.Bold = true;
- Button1.ForeColor = System.Drawing.Color.Green;
- }
- }
- protected void Button1_Click(object sender, EventArgs e) {
- Label1.Text = "City: " + TextBox1.Text.ToString();
- Label1.Text += "<br />Zip: " + TextBox2.Text.ToString();
- }
- }
No comments:
Post a Comment