zoukankan
html css js c++ java
Vs.net 2005控件(Web Controls)小例值外传
Default.apsx 前台代码:
<%
@ Register TagPrefix
=
"
uc1
"
TagName
=
"
LogInOutControl
"
Src
=
"
LogInOutControl.ascx
"
%>
<%
@ Page Language
=
"
C#
"
AutoEventWireup
=
"
true
"
CodeFile
=
"
Default.aspx.cs
"
Inherits
=
"
_Default
"
%>
<!
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
>
Untitled Page
</
title
>
</
head
>
<
body
>
<
form id
=
"
form1
"
runat
=
"
server
"
>
<
div
>
<
FONT face
=
"
宋体
"
>
<
uc1:LogInOutControl id
=
"
LogInOutControl1
"
runat
=
"
server
"
>
</
uc1:LogInOutControl
>
<
asp:Label id
=
"
LabelMsg
"
runat
=
"
server
"
></
asp:Label
>
<
asp:DropDownList id
=
"
DropDownList1
"
runat
=
"
server
"
AutoPostBack
=
"
True
"
OnSelectedIndexChanged
=
"
DropDownList1_SelectedIndexChanged
"
>
<
asp:ListItem Value
=
"
0
"
Selected
=
"
True
"
>
中文
</
asp:ListItem
>
<
asp:ListItem Value
=
"
1
"
>
英文
</
asp:ListItem
>
</
asp:DropDownList
></
FONT
>
</
div
>
</
form
>
</
body
>
</
html
>
后台代码:
using
System;
using
System.Data;
using
System.Configuration;
using
System.Web;
using
System.Web.Security;
using
System.Web.UI;
using
System.Web.UI.WebControls;
using
System.Web.UI.WebControls.WebParts;
using
System.Web.UI.HtmlControls;
public
partial
class
_Default : System.Web.UI.Page
{
protected
void
Page_Load(
object
sender, EventArgs e)
{
this
.LogInOutControl1.LogInOutClick
+=
new
LogInOutClickHandler(LogInOutControl1_LogInOutClick);
}
private
void
LogInOutControl1_LogInOutClick(
object
sender, LogInOutEventArgs e)
{
switch
(e.Type)
{
case
LogInClickType.LongIn:
this
.LabelMsg.Text
=
e.UserName
+
"
你点击了登录按钮,操作结果:
"
+
e.Result.ToString();
break
;
case
LogInClickType.LongOut:
this
.LabelMsg.Text
=
"
你点击了注销按钮,操作结果:
"
+
e.Result.ToString();
break
;
}
}
protected
void
DropDownList1_SelectedIndexChanged(
object
sender, System.EventArgs e)
{
this
.LogInOutControl1.Lg
=
(Language)
this
.DropDownList1.SelectedIndex;
}
}
控件前台代码:
<%
@ Control Language
=
"
C#
"
AutoEventWireup
=
"
true
"
CodeFile
=
"
LogInOutControl.ascx.cs
"
Inherits
=
"
LogInOutControl
"
%>
<
TABLE id
=
"
Table1
"
style
=
"
FONT-SIZE: 9pt; WIDTH: 183px; HEIGHT: 125px
"
cellSpacing
=
"
1
"
cellPadding
=
"
1
"
width
=
"
183
"
align
=
"
center
"
border
=
"
1
"
>
<
TR
>
<
TD height
=
"
20
"
>
<
asp:Label id
=
"
LabelUser
"
runat
=
"
server
"
>
用户:
</
asp:Label
>
<
asp:TextBox id
=
"
TextBoxUserName
"
Width
=
"
128px
"
runat
=
"
server
"
></
asp:TextBox
></
TD
>
</
TR
>
<
TR
>
<
TD height
=
"
20
"
><
FONT face
=
"
宋体
"
>
<
asp:Label id
=
"
LabelPassword
"
runat
=
"
server
"
>
密码:
</
asp:Label
>
<
asp:TextBox id
=
"
TextBoxPassword
"
Width
=
"
128px
"
runat
=
"
server
"
TextMode
=
"
Password
"
></
asp:TextBox
></
FONT
></
TD
>
</
TR
>
<
TR
>
<
TD align
=
"
center
"
height
=
"
20
"
><
FONT face
=
"
宋体
"
>
<
asp:Button id
=
"
ButtonLogIn
"
Width
=
"
50px
"
Text
=
"
登录
"
runat
=
"
server
"
OnClick
=
"
ButtonLogIn_Click
"
></
asp:Button
>
<
asp:Button id
=
"
ButtonLogOut
"
Width
=
"
49px
"
Text
=
"
注销
"
runat
=
"
server
"
OnClick
=
"
ButtonLogOut_Click
"
></
asp:Button
></
FONT
></
TD
>
</
TR
>
</
TABLE
>
控件后台代码:
using
System;
using
System.Data;
using
System.Configuration;
using
System.Collections;
using
System.Web;
using
System.Web.Security;
using
System.Web.UI;
using
System.Web.UI.WebControls;
using
System.Web.UI.WebControls.WebParts;
using
System.Web.UI.HtmlControls;
public
delegate
void
LogInOutClickHandler(
object
sender, LogInOutEventArgs e);
public
partial
class
LogInOutControl : System.Web.UI.UserControl
{
public
event
LogInOutClickHandler LogInOutClick;
private
Language language;
public
void
ChangeLanguage(Language language)
{
this
.Lg
=
language;
}
public
Language Lg
{
set
{
if
(value
!=
this
.language)
{
if
(value
==
Language.English)
{
this
.LabelUser.Text
=
"
User:
"
;
this
.LabelPassword.Text
=
"
Password:
"
;
this
.ButtonLogIn.Text
=
"
LogIn
"
;
this
.ButtonLogOut.Text
=
"
LogOut
"
;
}
else
{
this
.LabelUser.Text
=
"
用户:
"
;
this
.LabelPassword.Text
=
"
密码:
"
;
this
.ButtonLogIn.Text
=
"
登录
"
;
this
.ButtonLogOut.Text
=
"
注销
"
;
}
}
}
}
protected
void
Page_Load(
object
sender, EventArgs e)
{
if
(
this
.LabelUser.Text
==
"
User:
"
)
this
.language
=
Language.English;
else
this
.language
=
Language.Chinese;
}
private
void
OnLogInOutClick(
object
sender, LogInOutEventArgs e)
{
e.UserName
=
this
.TextBoxUserName.Text;
if
(LogInOutClick
!=
null
)
LogInOutClick(
this
, e);
}
protected
void
ButtonLogIn_Click(
object
sender, EventArgs e)
{
OnLogInOutClick(
this
,
new
LogInOutEventArgs(LogInClickType.LongIn, CustomValidate(
this
.TextBoxUserName.Text,
this
.TextBoxPassword.Text)));
}
private
bool
CustomValidate(
string
p,
string
p_2)
{
return
true
;
}
protected
void
ButtonLogOut_Click(
object
sender, EventArgs e)
{
OnLogInOutClick(
this
,
new
LogInOutEventArgs(LogInClickType.LongOut,
true
));
}
}
用于控件和主页面之间传值用的类
using
System;
using
System.Data;
using
System.Configuration;
using
System.Web;
using
System.Web.Security;
using
System.Web.UI;
using
System.Web.UI.WebControls;
using
System.Web.UI.WebControls.WebParts;
using
System.Web.UI.HtmlControls;
/**/
///
<summary>
///
Summary description for LogInOutEventArgs
///
</summary>
public
class
LogInOutEventArgs : EventArgs
{
private
LogInClickType type;
private
bool
result;
private
string
userName;
public
LogInOutEventArgs(LogInClickType type,
bool
result):
base
()
{
this
.type
=
type;
this
.result
=
result;
}
public
LogInClickType Type
{
get
{
return
this
.type; }
}
public
bool
Result
{
get
{
return
this
.result; }
}
public
string
UserName
{
get
{
return
userName; }
set
{ userName
=
value; }
}
}
public
enum
LogInClickType :
int
{
LongIn,
LongOut
}
public
enum
Language
{
Chinese,
English
}
查看全文
相关阅读:
基于maven的profile实现动态选择配置文件
[公告]博客迁移通知
itellij idea导入web项目并部署到tomcat
DWR实现后台推送消息到web页面
DWR实现扫一扫登录功能
微信企业号开发[目录]
微信企业号开发[一]——创建应用
微信企业号开发[三]——调用微信接口
微信企业号开发[二]——获取用户信息
JavaScript编码规范指南
原文地址:https://www.cnblogs.com/RuiLei/p/530741.html
最新文章
java触发full gc的几种情况概述
常见的java内存溢出情况
JVM年轻代,老年代,永久代详解
Java线程池详解及常用方法
使用synchronized修饰静态方法和非静态方法有什么区别
阿里云短信发送触发天级流量及解决办法
elasticsearch扩展ik分词器词库
Idea+Jconsole实现线程监控
Java 泛型详解
深入理解幂等性及Restful风格API的幂等性问题详解
热门文章
GitHub笔记(五)——忽略文件、配置别名、搭建服务器
GitHub笔记(四)——标签管理
GitHub笔记(三)——分支管理和多人协作
GitHub笔记(二)——远程仓库的操作
GitHub笔记(一)——本地库基础操作
JavaScript学习笔记(八)—— 补
JavaScript学习笔记(七)—— 再说函数
JavaScript学习笔记(六)—— 异步编码
JavaScript学习笔记(五)——类型、转换、相等、字符串
JavaScript学习笔记(四)——DOM
Copyright © 2011-2022 走看看