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
}
查看全文
相关阅读:
【ZJOI2007】棋盘制作 BZOJ1057
【ZJOI2008】 树的统计 count
【JSOI2007】麻将 bzoj 1028
【省选】省选黄色预警
【ZJOI2013】k大数查询 BZOJ 3110
【HNOI2008】Cards BZOJ 1004
【JSOI2010】Group 部落划分 BZOJ 1821
NOIp2014 解题报告
CH Round #56
CH Round #55
原文地址:https://www.cnblogs.com/RuiLei/p/530741.html
最新文章
CMDB--autoclient
自动化运维
小程序的登陆和授权
# 微信小程序
Git
区别MVC和mtv
drf框架
FORM组件
cookie 和 session
数据库表自动生成 model 类
热门文章
http的三次握手与四次挥手
html5 SVG
CSS三列自适应布局(两边宽度固定,中间自适应)
css的position属性
js中this的理解
使用new时,会发生什么?
CSS的响应式布局
理解js中的原型链
js立即执行函数
js的闭包
Copyright © 2011-2022 走看看