v2.0,再写个asp.net小例子,说明内容与行为如何分离

缪军 2010-07-04 09:47:06

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="test.aspx.cs" Inherits="test" %>

<!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></title>
</head>
<body>
<form id="form1" runat="server">

<asp:TextBox ID="txtTest" runat="server"></asp:TextBox>
<asp:Button ID="btnTest" runat="server" UseSubmitBehavior="false" />
</form>
</body>
</html>






using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class test : System.Web.UI.Page
{
#region Properties
protected System.Web.UI.WebControls.Label lblTest = new Label();
#endregion Properties

//可以自己写个Page_Load
protected void MyPageLoad(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
this.btnTest.Text = "Click Me";
//虽然是动态添加的控件,注意运行时,属性是持久的
this.lblTest.Text = "I am lblTest";
}

}

//接管OnInit,自己加点东西到页面
protected override void OnInit(EventArgs e)
{
this.InitializeComponent();
base.OnInit(e);
}

protected void InitializeComponent()
{
//注册控件
this.Controls.Add(this.lblTest);
//注册事件
this.btnTest.Click += new EventHandler(btnTest_Click);
//注册自定义的Page_Load
this.Load += new EventHandler(MyPageLoad);
}



protected void btnTest_Click(object sender, EventArgs e)
{
this.txtTest.Text = "The Button Have Been Clicked";
}

}




上一篇:写个JavaScript小例子,说明内容与行为如何分离
http://topic.csdn.net/u/20100702/08/b0d6c989-eba2-42e3-98b3-63120841c31b.html


...全文
395 20 打赏 收藏 转发到动态 举报
写回复
用AI写文章
20 条回复
切换为时间正序
请发表友善的回复…
发表回复
daiqx 2011-01-05
  • 打赏
  • 举报
回复
好帖子
IHandler 2010-07-05
  • 打赏
  • 举报
回复
加油- - -
leejelen 2010-07-05
  • 打赏
  • 举报
回复
学习了,顶上去!
lilin8905 2010-07-05
  • 打赏
  • 举报
回复
qiqishardgel 2010-07-05
  • 打赏
  • 举报
回复
谢谢分享,帮顶!
kkbac 2010-07-04
  • 打赏
  • 举报
回复
缪军 2010-07-04
  • 打赏
  • 举报
回复
[Quote=引用 9 楼 wiki14 的回复:]
支持分享。
[/Quote]

对高手的要求是:提点意见或建议
wiki14 2010-07-04
  • 打赏
  • 举报
回复
支持分享。
nextuntil 2010-07-04
  • 打赏
  • 举报
回复
顶一个。
xingshungames 2010-07-04
  • 打赏
  • 举报
回复
perfe_ct 2010-07-04
  • 打赏
  • 举报
回复
顶到起~!
小_虎 2010-07-04
  • 打赏
  • 举报
回复
FollowMe_NGU 2010-07-04
  • 打赏
  • 举报
回复
FollowMe_NGU 2010-07-04
  • 打赏
  • 举报
回复
哈喽Baby 2010-07-04
  • 打赏
  • 举报
回复
S_trance 2010-07-04
  • 打赏
  • 举报
回复
PL
SF
dengNeeo 2010-07-04
  • 打赏
  • 举报
回复
支持分享
嘿嘿
lo_back___ 2010-07-04
  • 打赏
  • 举报
回复
学习!~

62,074

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧