System.Web.UI.HtmlControls.HtmlGenericControl 非常有用的控件
Posted on 2005-04-22 09:33 GaoJie[高杰] 阅读(1946) 评论(0) 编辑 收藏 举报
Using Guide:
1. 编辑好HTML文件。
2. 这些 HTML中的控件(一般都是客户端控件),只要加上 两个属性就变成 Server side control.
例如增加 id=Body runat=server
3. 在 xxx.aspx.cs文件中增加多 Body的说明 protected System.Web.UI.HtmlControls.HtmlGenericControl Body;
4. 然后就可以在 xxx.aspx.cs文件中书写 Body.Attributes["bgcolor"] = "Red";
sample code:
1. 编辑好HTML文件。
2. 这些 HTML中的控件(一般都是客户端控件),只要加上 两个属性就变成 Server side control.
例如增加 id=Body runat=server
3. 在 xxx.aspx.cs文件中增加多 Body的说明 protected System.Web.UI.HtmlControls.HtmlGenericControl Body;
4. 然后就可以在 xxx.aspx.cs文件中书写 Body.Attributes["bgcolor"] = "Red";
sample code:
<%@ Page language="c#" Codebehind="login.aspx.cs" AutoEventWireup="false" Inherits="com.Siemens.medgrp.MDP.Framework.login" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>login</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body id=Body runat=server>
<form id="Form1" method="post" runat="server">
<asp:TextBox id="TextBox1" style="Z-INDEX: 101; LEFT: 176px; POSITION: absolute; TOP: 112px"
runat="server"></asp:TextBox>
<asp:Button id="Button1" style="Z-INDEX: 102; LEFT: 168px; POSITION: absolute; TOP: 256px" runat="server"
Text="Submit"></asp:Button>
<asp:TextBox id="TextBox2" style="Z-INDEX: 103; LEFT: 176px; POSITION: absolute; TOP: 152px"
runat="server"></asp:TextBox>
<asp:TextBox id="TextBox3" style="Z-INDEX: 104; LEFT: 176px; POSITION: absolute; TOP: 192px"
runat="server"></asp:TextBox>
<asp:Label id="Label1" style="Z-INDEX: 105; LEFT: 104px; POSITION: absolute; TOP: 112px" runat="server">User ID</asp:Label>
<asp:Label id="Label2" style="Z-INDEX: 106; LEFT: 104px; POSITION: absolute; TOP: 152px" runat="server">Password</asp:Label>
<asp:Label id="Label3" style="Z-INDEX: 107; LEFT: 104px; POSITION: absolute; TOP: 192px" runat="server">Country</asp:Label>
<asp:Label id="Label4" style="Z-INDEX: 108; LEFT: 128px; POSITION: absolute; TOP: 64px" runat="server">Med Dealer Portal Login Test</asp:Label>
</form>
</body>
</HTML>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>login</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body id=Body runat=server>
<form id="Form1" method="post" runat="server">
<asp:TextBox id="TextBox1" style="Z-INDEX: 101; LEFT: 176px; POSITION: absolute; TOP: 112px"
runat="server"></asp:TextBox>
<asp:Button id="Button1" style="Z-INDEX: 102; LEFT: 168px; POSITION: absolute; TOP: 256px" runat="server"
Text="Submit"></asp:Button>
<asp:TextBox id="TextBox2" style="Z-INDEX: 103; LEFT: 176px; POSITION: absolute; TOP: 152px"
runat="server"></asp:TextBox>
<asp:TextBox id="TextBox3" style="Z-INDEX: 104; LEFT: 176px; POSITION: absolute; TOP: 192px"
runat="server"></asp:TextBox>
<asp:Label id="Label1" style="Z-INDEX: 105; LEFT: 104px; POSITION: absolute; TOP: 112px" runat="server">User ID</asp:Label>
<asp:Label id="Label2" style="Z-INDEX: 106; LEFT: 104px; POSITION: absolute; TOP: 152px" runat="server">Password</asp:Label>
<asp:Label id="Label3" style="Z-INDEX: 107; LEFT: 104px; POSITION: absolute; TOP: 192px" runat="server">Country</asp:Label>
<asp:Label id="Label4" style="Z-INDEX: 108; LEFT: 128px; POSITION: absolute; TOP: 64px" runat="server">Med Dealer Portal Login Test</asp:Label>
</form>
</body>
</HTML>
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
namespace com.Siemens.medgrp.MDP.Framework
{
/// <summary>
/// Summary description for login.
/// </summary>
public class login : System.Web.UI.Page
{
protected System.Web.UI.WebControls.TextBox TextBox1;
protected System.Web.UI.WebControls.Button Button1;
protected System.Web.UI.WebControls.TextBox TextBox2;
protected System.Web.UI.WebControls.TextBox TextBox3;
protected System.Web.UI.WebControls.Label Label1;
protected System.Web.UI.WebControls.Label Label2;
protected System.Web.UI.WebControls.Label Label4;
protected System.Web.UI.WebControls.Label Label3;
protected System.Web.UI.HtmlControls.HtmlGenericControl Body;
private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
Body.Attributes["bgcolor"] = "Red";
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.Button1.Click += new System.EventHandler(this.Button1_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void Button1_Click(object sender, System.EventArgs e)
{
this.Page.Session["UserName"]="GaoJie";
this.Page.Session["Password"]="Password1";
this.Page.Session["logined"]="sdssfsdf";
this.Page.Response.Redirect("Framework_InterpretSite.aspx?country=China",true);
//this.Page.Response.Redirect("header.aspx",true);
}
}
}
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
namespace com.Siemens.medgrp.MDP.Framework
{
/// <summary>
/// Summary description for login.
/// </summary>
public class login : System.Web.UI.Page
{
protected System.Web.UI.WebControls.TextBox TextBox1;
protected System.Web.UI.WebControls.Button Button1;
protected System.Web.UI.WebControls.TextBox TextBox2;
protected System.Web.UI.WebControls.TextBox TextBox3;
protected System.Web.UI.WebControls.Label Label1;
protected System.Web.UI.WebControls.Label Label2;
protected System.Web.UI.WebControls.Label Label4;
protected System.Web.UI.WebControls.Label Label3;
protected System.Web.UI.HtmlControls.HtmlGenericControl Body;
private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
Body.Attributes["bgcolor"] = "Red";
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.Button1.Click += new System.EventHandler(this.Button1_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void Button1_Click(object sender, System.EventArgs e)
{
this.Page.Session["UserName"]="GaoJie";
this.Page.Session["Password"]="Password1";
this.Page.Session["logined"]="sdssfsdf";
this.Page.Response.Redirect("Framework_InterpretSite.aspx?country=China",true);
//this.Page.Response.Redirect("header.aspx",true);
}
}
}