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
}
查看全文
相关阅读:
Java 对象的封装,继承,抽象,接口写法
python 3.7 方向键乱码
yocto doc
为什么要使用yocto
ltp-ddt的makefile结构
Git 常用命令列表
Makefile依赖关系中的竖线“|”
makefile 双冒号规则
ltp makefile 解析
makefile 变量展开
原文地址:https://www.cnblogs.com/RuiLei/p/530741.html
最新文章
【C语言】(for循环嵌套)找出1000以内的水仙花数
欧盟议会:尝试将智能机器人送上法庭
为什么苹果公司没有产生更多的亿万富翁
外媒:比特币市场正式开放至16亿给穆斯林
这些方法能快速提高你搜索引擎排名
不得不信!黑客通过电源线也可以窃取计算机数据
特斯拉频频出现致命事故,自动驾驶真的这么可怕吗?
为打击国际恐怖组织!俄罗斯阻止电报应用程序加密
外媒:比特币将是一场灾难,而不是经济
英国已有500万宽带用户接入并开始使用IPv6技术
热门文章
智能手机安全:黑客是如何秘密控制你手机号码
UPD链接实现稳健传输案例
IO字节流与字符流的操作
IO流基础,创建File对象与方法是用
java三个时间类常用法
HashMap集合嵌套集合方法四种
Map,HashMap五种遍历方法
Collection接口和list,set子类
Vue事件修饰符,.capture关键字详解
Java 多态
Copyright © 2011-2022 走看看