Asp.net 用户控件添加自定义事件
对于用户控件的使用有这样的特点。就是,当我们要求一个用户控件要实现特定的功能的时候,他可以在整个网站里面的页面上任意拖拽。但是,他的功能相对固定,也就是说在ascx文件中的代码是写死的,一旦要实现其他功能,就要将整个用户控件重做。这里介绍一种方法,要用户控件的可重复使用性更强。
前台代码:
就是一个简单的登录控件
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="LoginControl.ascx.cs" Inherits="LoginControl" %>
<table border="1">
<tr>
<td colspan="3" style="background-color: #0099ff; text-align: center">
<strong>用户登录</strong></td>
</tr>
<tr>
<td style="width: 100px">
用户名:</td>
<td colspan="2">
<asp:TextBox ID="txtName" runat="server" ValidationGroup="group1"></asp:TextBox></td>
</tr>
<tr>
<td style="width: 100px; height: 30px">
密码:</td>
<td colspan="2" style="height: 30px">
<asp:TextBox ID="txtPassword" runat="server" TextMode="Password"></asp:TextBox></td>
</tr>
<tr>
<td colspan="3" style="text-align: center">
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="txtName"
ErrorMessage="用户名为必填项" ValidationGroup="group1"></asp:RequiredFieldValidator></td>
</tr>
<tr>
<td style="width: 100px">
<asp:Button ID="Button3" runat="server" Text="Button" /></td>
<td style="width: 100px; text-align: center">
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="登录" ValidationGroup="group1"
相关新闻>>
- 发表评论
-
- 最新评论 进入详细评论页>>
今日头条
更多>>您可能感兴趣的文章
- MVC3+Entity Framework 实现投票系统(二)
- 使用ASP.NET MVC3+EF+Jquery制作文字直播系统(四
- asp.net DataTable和Dataset序列化成Json格式
- 聊聊.net程序设计——浅谈使用VS2010建模拓展(下
- JQuery+Asp.net MVC实现用户名重名查询
- Spring MVC 3.0.5+Spring 3.0.5+MyBatis3.0.4全注
- Web Service学习笔记(4)
- .net架构的最后思考(箴言)
- .NET设计模式:工厂方法模式(Factory Method)[1]
- .NET简谈互操作(四:基础知识之Dispose非托管内存



