易截截图软件、单文件、免安装、纯绿色、仅160KB

使用ASP.NET中的用户控件

用户控件是ASP.NET中很重要的一部分,使用它可以提高程序代码的重用性,即一个用户控件在网页、用户控件或控件的内部都可以再次使用。本实例介绍用户登录的用户控件也可以在网站的任何地方再次使用。
技术要点
本实例介绍如何在ASP.NET中创建用户控件、如何使用用户控件,以及如何在用户控件中定义公开属性的实现方法。
跟我做
1.创建新ASP.NET应用程序
在Visual Studio .NET 2003集成开发环境中创建新的ASP.NET Web应用程序,命名为Example_12_4。
2.创建用户登录用户控件MyUserControl.ascx
在应用程序Example_12_4中添加1个用户控件,它的名称为MyUserControl.ascx,并在用户控件上添加2个TextBox控件和2个Button控件,它们的名称分别为tUserName、tPassword、UserLoginBtn和CancelBtn。
控件tUserName和tPassword分别用来输入用户名称和用户密码;控件UserLoginBtn和CancelBtn实现用户登录功能和取消登录功能。用户登录用户控件MyUserControl.ascx的设计界面如图12-9所示。
图12-9  用户控件MyUserControl.ascx的设计界面
用户控件MyUserControl.ascx的HTML设计代码如下:
<%@ Control Language="c#" AutoEventWireup="false"
Codebehind="MyUserControl.ascx.cs" Inherits="
Example_12_4.MyUserControl"
TargetSchema="http://schemas.microsoft.com/intellisense/ie5"%>
<td colspan="2">用户登录用户控件:</td>
<td width="150" align="right">用户名称:</td>
<asp:TextBox id="tUserName" runat="server" width="200"></asp:TextBox>
<td width="150" align="right">用户密码:</td>
<asp:TextBox id="tPassword" runat="server" width="200"
TextMode="Password"></asp:TextBox>
<asp:Button id="UserLoginBtn" runat="server" Text="确  定"></asp:Button>
<asp:Button id="CancelBtn" runat="server" Text="取  消"></asp:Button>
3.设置用户登录用户控件MyUserControl.ascx的事件和函数
在应用程序Example_12_4中添加用户控件的属性UserName和Password,分别表示用户控件中控件UserName和控件Password的属性Text的值。属性UserName和属性Password的程序代码如下:
//添加属性UserName
public String UserName
{
get{return(tUserName.Text);}       &n


相关文档:

ASP.NET MVC Best Practices 27+

12 ASP.NET MVC Best Practices
M
DomainModel != ViewModel
Use ActionFilters for “shared” data
V
Do NEVER user code-behind
Write HTML each time you can
If there is an if, write an HtmlHelper
Choose your view engine carefully
C
Delete the AccountController
Isolate Controllers fro ......

asp.net 页面右下角弹出类似QQ或MSN的消息提示

<HTML><HEAD>
<TITLE>网页特效观止|JsCode.CN|---页面右下角弹出类似QQ或MSN的消息提示</TITLE>
<SCRIPT language=JavaScript>
<!--
/**//*
**    ==================================================================================================
**&nbs ......

asp.net性能

 1.关闭不必要的Session
<%@ Page EnableSessionState="flase"%>
2.关闭不必要的ViewState
<asp:DataGrid EnableViewState="false" runat="server">
如果页面级
<%@ Page EnableViewState="false"%>
3.不要使用Exception控制程序流程
  Exception是很耗资源的
4.禁用VB和JScript动态数 ......

asp.net错误处理

 出现错误发送Email
可以在Global.asax的void Application_Error(Object sender,EventArgs e)
{
 //用到了Ssytem.Net.Mail
 MailMessage mail=new MailMessage();
 mail.from=new MailAddress("automated@contoso.com");
 mail.Subject="SIte Error at" +DateTime.Now;
 mail.Body="E ......

Asp.net网站开发架构设计要求


网站文件名:
1、 网站文件名以标准英文单词描述业务内容。如果1个英文单词无法描述,可以增加2个或者3个,但尽量为完全单词,例如article.aspx/ articleView.aspx / articleList.aspx 等。
2、 文件名尽量不用数字描述。
3、 文件名尽量不能太长,以不超过20个字母为宜。
4、 图片文件名尽量描述图片内容分类。尽量 ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号