aspnet项目开发教程 使用ASP.NET中的用户控件[1]
![aspnet项目开发教程 使用ASP.NET中的用户控件[1]](http://img.zhputi.com/uploads/6a53/6a535094e59a88b621916428b90540e833161.jpg)
使用ASP.NET中的用户控件[1]
——此文章摘自《ASP NET网络数据库开发实例精解》定价 ¥ 特价 ¥ 详细>>//track linktech cn/?m_id=dangdang&a_id=A &l= &l_type = width= height= border= nosave>用户控件是ASP NET中很重要的一部分 使用它可以提高程序代码的重用性 即一个用户控件在网页 用户控件或控件的内部都可以再次使用 本实例介绍用户登录的用户控件也可以在网站的任何地方再次使用
本实例介绍如何在ASP NET中创建用户控件 如何使用用户控件 以及如何在用户控件中定义公开属性的实现方法
.创建新ASP NET应用程序
在Visual Studio NET 集成开发环境中创建新的ASP NET Web应用程序 命名为Example_ _
.创建用户登录用户控件MyUserControl ascx
在应用程序Example_ _ 中添加 个用户控件 它的名称为MyUserControl ascx 并在用户控件上添加 个TextBox控件和 个Button控件 它们的名称分别为tUserName tPassword UserLoginBtn 和CancelBtn
控件tUserName和tPassword分别用来输入用户名称和用户密码 控件UserLoginBtn和CancelBtn实现用户登录功能和取消登录功能 用户登录用户控件MyUserControl ascx的设计界面如图 所示
//develop csai cn/dotnet_ASP/images/ gif >图 用户控件MyUserControl ascx的设计界面
用户控件MyUserControl ascx的HTML设计代码如下 <%@ Control Language= c# AutoEventWireup= false Codebehind= MyUserControl ascx cs Inherits= Example_ _ MyUserControl TargetSchema= //schemas microsoft /intellisense/ie %> <td colspan= >用户登录用户控件 </td> <td width= align= right >用户名称 </td> <asp:TextBox id= tUserName runat= server width= ></asp:TextBox> <td width= align= right >用户密码 </td> <asp:TextBox id= tPassword runat= server width= TextMode= Password ></asp:TextBox> <asp:Button id= UserLoginBtn runat= server Text= 确 定 ></asp:Button> <asp:Button id= CancelBtn runat= server Text= 取 消 ></asp:Button>
.设置用户登录用户控件MyUserControl ascx的事件和函数
在应用程序Example_ _ 中添加用户控件的属性UserName和Password 分别表示用户控件中控件UserName和控件Password的属性Text的值 属性UserName和属性Password的程序代码如下
lishixinzhi/Article/program/net/201311/15336