Asp.net 随记

1 sender 指的是触发事件的控件

example:

Button btn=(Button)sender;

btn.Content="你点我了!";

//button2.Content="你点我了";

法一能让两个个按钮出现事件的反应,而法二只能让一个出现

2 常用控件的通用属性

!Visibility控件是否可见:枚举类型:Visible表示可见,Collapsed表示不可见

@IsEnabled:控件是否可用:bool类型;

#Background背景色;

$FontSize字体大小

3Textbox的属性:

1 IsReadOnly="true";只读

2TextWrapping="Wrap";可多行输入

3MaxLength="5";限制输入长度

4 基本控件及其运用代码

1 控件的ID应该遵循良好的命名规范,以便维护

2 超链接控件(HeperLink)

代码如下:

<asp:HyperLink ID="HyperLink1" runat="server"  ImageUrl=http://www.shangducms.com/images/cms.jpg                //ImageUrl  Navlgate 属性

NavigateUrl="http://shangducms.com">

HyperLink</asp:HyperLink>

3 DropDownList控件

代码如下:

<html xmlns="http://www.w3.org/1999/xhtml">

<head runat="server">

<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>

<title></title>

</head>

<body>

<form id="form1" runat="server">

<div>

<asp:DropDownList ID="DropDownList1" runat="server" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged">

</asp:DropDownList>

</div>

</form>

</body>

</html>

using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;

using System.Web.UI;

using System.Web.UI.WebControls;

public partial class kongjiandama : System.Web.UI.Page

{

protected void Page_Load(object sender, EventArgs e)

{

bind();

}

protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)

{

}

private void bind()

{

ListItem li = new ListItem();

li.Text = "qq";

li.Value = "qq";

li.Enabled = true;

DropDownList1.Items.Add(li);

ListItem l2=new ListItem();

l2.Text="sohu";

l2.Value="sohu";

li.Enabled=true;

DropDownList1.Items.Add(l2);

}

}方法一

<html xmlns="http://www.w3.org/1999/xhtml">

<head runat="server">

<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>

<title></title>

</head>

<body>

<form id="form1" runat="server">

<div>

<asp:DropDownList ID="DropDownList1" runat="server" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged">

<asp:ListItem Value="qq" Text="qq" Enabled="true"></asp:ListItem>

<asp:ListItem Value="sohu" Text="sohu" Enabled="true"></asp:ListItem>

</asp:DropDownList>

</div>

</form>

</body>

</html>

方法二

可是使用DropDownList控件实现当用户选择不同的值的时候实现超链接怎么办 ??????

4 图像控件(image)

Alternate Text:备用文本

Image Align:图像对齐

ImageUrl:显示图像URl  //Image 不支持事件

代码如下:

<asp:Image ID="Image1" runat="server"

AlternateText="图片连接无效"  ImageAlign="Left" ImageUrl="~/kongjiandama.aspx"/>

5 文本框控件(TextBox)

1 AutoPostBack(自动回传)属性

2 EnableViewState(控件状态)属性

3 MaxLength(限制字符串长度)

4 ReadOnly(只读)

5 TextMode(单行,多行,密文)

6 按钮控件(Button,LinkButton,ImageButton)

7单选组控件

<html xmlns="http://www.w3.org/1999/xhtml">

<head runat="server">

<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>

<title></title>

</head>

<body>

<form id="form1" runat="server">

<div>

<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>

</div>

<asp:RadioButton ID="RadioButton1" runat="server"  GroupName="choose"

Text="Choose1" OnCheckedChanged="RadioButton1_CheckedChanged" AutoPostBack="true" />

<asp:RadioButton ID="RadioButton2" runat="server" GroupName="choose"

Text="Choose1" OnCheckedChanged="RadioButton1_CheckedChanged"  AutoPostBack="true"/>

</form>

</body>

</html>

using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;

using System.Web.UI;

using System.Web.UI.WebControls;

public partial class _520 : System.Web.UI.Page

{

protected void Page_Load(object sender, EventArgs e)

{

}

protected void RadioButton2_CheckedChanged1(object sender, EventArgs e)

{

Label1.Text = "第二个被选中";

}

protected void RadioButton1_CheckedChanged(object sender, EventArgs e)

{

Label1.Text = "第一个被选中";

}

}

8 DropDownList 列表控件

</head>

<body>

<form id="form1" runat="server">

<div>

<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="true" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged">

<asp:ListItem>1</asp:ListItem>

<asp:ListItem>2</asp:ListItem>

<asp:ListItem>3</asp:ListItem>

<asp:ListItem>4</asp:ListItem>

<asp:ListItem>5</asp:ListItem>

<asp:ListItem>6</asp:ListItem>

<asp:ListItem>7</asp:ListItem>

</asp:DropDownList>

</div>

<asp:Label ID="Label1" runat="server" Text="Label" ></asp:Label>

</form>

</body>

using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;

using System.Web.UI;

using System.Web.UI.WebControls;

public partial class _Default : System.Web.UI.Page

{

protected void Page_Load(object sender, EventArgs e)

{

}

protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)

{

Label1.Text="你选择了第"+DropDownList1.Text+"项";

}

}

9 ListBox 列表控件

<body>

<form id="form1" runat="server">

<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>

<br />

<asp:ListBox ID="ListBox1" runat="server" AutoPostBack="True" OnSelectedIndexChanged="ListBox1_SelectedIndexChanged" SelectionMode="Multiple">

<asp:ListItem>1</asp:ListItem>

<asp:ListItem>2</asp:ListItem>

<asp:ListItem>3</asp:ListItem>

<asp:ListItem>4</asp:ListItem>

</asp:ListBox>

</form>

</body>

protected void ListBox1_SelectedIndexChanged(object sender, EventArgs e)

{

Label1.Text = "你选择了第" + ListBox1.Text+"项";

}

如果需要实现让用户选择多个 L istBox

项,只需要设置 Select ionMod e 属性为“Mu lt ip le”即可

10BulletedList 列表控件

<body>

<form id="form1" runat="server">

<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>

<asp:BulletedList ID="BulletedList1" runat="server" OnClick="BulletedList1_Click">

<asp:ListItem>1</asp:ListItem>

<asp:ListItem>2</asp:ListItem>

<asp:ListItem>3</asp:ListItem>

<asp:ListItem>4</asp:ListItem>

</asp:BulletedList>

</form>

</body>

protected void BulletedList1_Click(object sender, BulletedListEventArgs e)

{

Label1.Text = "你选择了第" + BulletedList1.Text + "项";

}

11 日历控件(Calendar)

<body>

<form id="form1" runat="server">

<asp:Calendar ID="Calendar1" runat="server" BackColor="White" BorderColor="#999999" CellPadding="4" DayNameFormat="Shortest" Font-Names="Verdana" Font-Size="8pt" ForeColor="Black" Height="180px" OnSelectionChanged="Calendar1_SelectionChanged" Width="200px">

<DayHeaderStyle BackColor="#CCCCCC" Font-Bold="True" Font-Size="7pt" />

<NextPrevStyle VerticalAlign="Bottom" />

<OtherMonthDayStyle ForeColor="#808080" />

<SelectedDayStyle BackColor="#666666" Font-Bold="True" ForeColor="White" />

<SelectorStyle BackColor="#CCCCCC" />

<TitleStyle BackColor="#999999" BorderColor="Black" Font-Bold="True" />

<TodayDayStyle BackColor="#CCCCCC" ForeColor="Black" />

<WeekendDayStyle BackColor="#FFFFCC" />

</asp:Calendar>

<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>

</form>

</body>

protected void Calendar1_SelectionChanged(object sender, EventArgs e)

{

Label1.Text=

"现在的时间是:"+Calendar1.SelectedDate.Year.ToString()+"年"

+Calendar1.SelectedDate.Month.ToString()+"月"

+Calendar1.SelectedDate.Day.ToString()+"号"

+Calendar1.SelectedDate.Hour.ToString()+"点";

}

12 表单验证控件(RequiredFieldValidator)

<body>

<form id="form1" runat="server">

姓名:<asp:TextBox ID="TextBox1" runat="server" OnTextChanged="TextBox1_TextChanged"></asp:TextBox>

<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"  ControlToValidate=" TextBox1" ErrorMessage="必填字段不能为空">

</asp:RequiredFieldValidator>

<br/>

密码:

<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>

<br />

<asp:Button ID="Button1" runat="server" Text="Button" />

<br />

</form>

</body>

13 比较验证控件(CompareValidator)

<body>

<form id="form1" runat="server">

<div>

请输入生日:

<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>

<br />

毕业日期:

<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>

<asp:CompareValidator ID="CompareValidator1" runat="server"

ControlToCompare="TextBox2" ControlToValidate="TextBox1"

CultureInvariantValues="True" ErrorMessage="输入格式错误!请改正!"

Operator="GreaterThan"

Type="Date">

</asp:CompareValidator>

<br />

<asp:Button ID="Button1" runat="server" Text="Button" />

<br />

</div>

</form>

</body>

14 范围验证控件(RangeValidator)

<html>

<head>

<title></title>

</head>

<body>

请输入生日:<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>

<asp:RangeValidator ID="RangeValidator1" runat="server"

ControlToValidate="TextBox1" ErrorMessage="超出规定范围,请重新填写"

MaximumValue="2009/1/1" MinimumValue="1990/1/1" Type="Date">

</asp:RangeValidator>

<br />

<asp:Button ID="Button1" runat="server" Text="Button" />

</body>

</html>

15 验证组控件(ValidationSummary)

<body>

<form id="form1" runat="server">

姓名:

<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>

<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"

ControlToValidate="TextBox1" ErrorMessage="姓名为必填项">

</asp:RequiredFieldValidator>

<br />

身份证:

<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>

<asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server"

ControlToValidate="TextBox1" ErrorMessage="身份证号码错误"

ValidationExpression="\d{17}[\d|X]|\d{15}"></asp:RegularExpressionValidator>

<br />

<asp:Button ID="Button1" runat="server" Text="Button" />

<asp:ValidationSummary ID="ValidationSummary1" runat="server" />

</form>

</body>

16 导航控件

<html>

<head>

<title></title>

</head>

<body>

<asp:Menu ID="Menu1" runat="server">

<Items>

<asp:MenuItem Text="新建项" Value="新建项"></asp:MenuItem>

<asp:MenuItem Text="新建项" Value="新建项">

<asp:MenuItem Text="新建项" Value="新建项"></asp:MenuItem>

</asp:MenuItem>

<asp:MenuItem Text="新建项" Value="新建项">

<asp:MenuItem Text="新建项" Value="新建项"></asp:MenuItem>

</asp:MenuItem>

<asp:MenuItem Text="新建项" Value="新建项">

<asp:MenuItem Text="新建项" Value="新建项">

<asp:MenuItem Text="新建项" Value="新建项"></asp:MenuItem>

</asp:MenuItem>

</asp:MenuItem>

<asp:MenuItem Text="新建项" Value="新建项"></asp:MenuItem>

</Items>

</asp:Menu>

</body>

</html>

17 登录控件(Login)

<body>

<form id="form1" runat="server">

<div>

<asp:Login ID="Login1" runat="server" BackColor="#F7F7DE" BorderColor="#CCCC99" BorderStyle="Solid" BorderWidth="1px" Font-Names="Verdana" Font-Size="10pt">

<LayoutTemplate>

<table cellpadding="1" cellspacing="0" style="border-collapse:collapse;">

<tr>

<td>

<table cellpadding="0">

<tr>

<td align="center" colspan="2">登录</td>

</tr>

<tr>

<td align="right">

<asp:Label ID="UserNameLabel" runat="server" AssociatedControlID="UserName">用户名:</asp:Label>

</td>

<td>

<asp:TextBox ID="UserName" runat="server"></asp:TextBox>

<asp:RequiredFieldValidator ID="UserNameRequired" runat="server" ControlToValidate="UserName" ErrorMessage="必须填写“用户名”。" ToolTip="必须填写“用户名”。" ValidationGroup="Login1">*</asp:RequiredFieldValidator>

</td>

</tr>

<tr>

<td align="right">

<asp:Label ID="PasswordLabel" runat="server" AssociatedControlID="Password">密码:</asp:Label>

</td>

<td>

<asp:TextBox ID="Password" runat="server" TextMode="Password"></asp:TextBox>

<asp:RequiredFieldValidator ID="PasswordRequired" runat="server" ControlToValidate="Password" ErrorMessage="必须填写“密码”。" ToolTip="必须填写“密码”。" ValidationGroup="Login1">*</asp:RequiredFieldValidator>

</td>

</tr>

<tr>

<td colspan="2">

<asp:CheckBox ID="RememberMe" runat="server" Text="下次记住我。" />

</td>

</tr>

<tr>

<td align="center" colspan="2" style="color:Red;">

<asp:Literal ID="FailureText" runat="server" EnableViewState="False"></asp:Literal>

</td>

</tr>

<tr>

<td align="right" colspan="2">

<asp:Button ID="LoginButton" runat="server" CommandName="Login" Text="登录" ValidationGroup="Login1" />

</td>

</tr>

</table>

</td>

</tr>

</table>

</LayoutTemplate>

<TitleTextStyle BackColor="#6B696B" Font-Bold="True" ForeColor="#FFFFFF" />

</asp:Login>

</div>

</form>

</body>

18 登录状态控件(LoginStatus)

<asp:LoginStatus ID="LoginStatus1" runat="server" />

19 密码更改控件(ChangePassword)

<body>

<form id="form1" runat="server">

<div>

<asp:ChangePassword ID="ChangePassword1" runat="server">

<ChangePasswordTemplate>

<table cellpadding="1" cellspacing="0" style="border-collapse:collapse;">

<tr>

<td>

<table cellpadding="0">

<tr>

<td align="center" colspan="2">更改密码</td>

</tr>

<tr>

<td align="right">

<asp:Label ID="CurrentPasswordLabel" runat="server" AssociatedControlID="CurrentPassword">密码:</asp:Label>

</td>

<td>

<asp:TextBox ID="CurrentPassword" runat="server" TextMode="Password"></asp:TextBox>

<asp:RequiredFieldValidator ID="CurrentPasswordRequired" runat="server" ControlToValidate="CurrentPassword" ErrorMessage="必须填写“密码”。" ToolTip="必须填写“密码”。" ValidationGroup="ChangePassword1">*</asp:RequiredFieldValidator>

</td>

</tr>

<tr>

<td align="right">

<asp:Label ID="NewPasswordLabel" runat="server" AssociatedControlID="NewPassword">新密码:</asp:Label>

</td>

<td>

<asp:TextBox ID="NewPassword" runat="server" TextMode="Password"></asp:TextBox>

<asp:RequiredFieldValidator ID="NewPasswordRequired" runat="server" ControlToValidate="NewPassword" ErrorMessage="必须填写“新密码”。" ToolTip="必须填写“新密码”。" ValidationGroup="ChangePassword1">*</asp:RequiredFieldValidator>

</td>

</tr>

<tr>

<td align="right">

<asp:Label ID="ConfirmNewPasswordLabel" runat="server" AssociatedControlID="ConfirmNewPassword">确认新密码:</asp:Label>

</td>

<td>

<asp:TextBox ID="ConfirmNewPassword" runat="server" TextMode="Password"></asp:TextBox>

<asp:RequiredFieldValidator ID="ConfirmNewPasswordRequired" runat="server" ControlToValidate="ConfirmNewPassword" ErrorMessage="必须填写“确认新密码”。" ToolTip="必须填写“确认新密码”。" ValidationGroup="ChangePassword1">*</asp:RequiredFieldValidator>

</td>

</tr>

<tr>

<td align="center" colspan="2">

<asp:CompareValidator ID="NewPasswordCompare" runat="server" ControlToCompare="NewPassword" ControlToValidate="ConfirmNewPassword" Display="Dynamic" ErrorMessage="“确认新密码”与“新密码”项必须匹配。" ValidationGroup="ChangePassword1"></asp:CompareValidator>

</td>

</tr>

<tr>

<td align="center" colspan="2" style="color:Red;">

<asp:Literal ID="FailureText" runat="server" EnableViewState="False"></asp:Literal>

</td>

</tr>

<tr>

<td align="right">

<asp:Button ID="ChangePasswordPushButton" runat="server" CommandName="ChangePassword" Text="更改密码" ValidationGroup="ChangePassword1" />

</td>

<td>

<asp:Button ID="CancelPushButton" runat="server" CausesValidation="False" CommandName="Cancel" Text="取消" />

</td>

</tr>

</table>

</td>

</tr>

</table>

</ChangePasswordTemplate>

</asp:ChangePassword>

</div>

</form>

</body>

时间: 2024-10-05 04:01:31

Asp.net 随记的相关文章

Visual Studio 2015 开发 ASP.NET 5 有何变化?(转)

出处:http://www.cnblogs.com/xishuai/p/visual-studio-2015-preview-asp-net-5-change.html 本篇博文目录: ASP.NET 5 模版 ASP.NET 5 目录结构 前端管理工具 无编译开发 Microsoft Git Provider 智能感知和错误信息 Smart Unit Testing 等待发现... Visual Studio 2015 Preview 版本部分说明: ASP.NET 5 Preview run

大家好

http://www.yugaopian.com/people/259723 http://www.yugaopian.com/people/259744 http://www.yugaopian.com/people/259783 http://www.yugaopian.com/people/259824 http://www.yugaopian.com/people/259839 http://www.yugaopian.com/people/259933 http://www.yugao

阿哥吗卡怪每次哦阿哥看啦过啦嘎开吃麻辣个啊蓝光

http://www.xx186.com/web/web_kpic.asp?id=156613http://www.xx186.com/web/web_kpic.asp?id=156608http://www.xx186.com/web/web_kpic.asp?id=156605http://www.xx186.com/web/web_kpic.asp?id=156602http://www.xx186.com/web/web_kpic.asp?id=156600http://www.xx18

风格更家霍建华

http://www.9ku.com/fuyin/daogaoo.asp?dgid=119864http://www.9ku.com/fuyin/daogaoo.asp?dgid=119867http://www.9ku.com/fuyin/daogaoo.asp?dgid=119876http://www.9ku.com/fuyin/daogaoo.asp?dgid=119879http://www.9ku.com/fuyin/daogaoo.asp?dgid=119883http://www

,了可美军以本合同个v分

http://shike.gaotie.cn/zhan.asp?zhan=%A1%FE%CE%F7%B0%B2%B8%B4%B7%BD%B5%D8%B7%D2%C5%B5%F5%A5%C6%AC%C4%C4%C0%EF%C2%F2Q%A3%BA%A3%B1%A3%B1%A3%B2%A3%B7%A3%B4%A3%B0%A3%B1%A3%B1%A3%B7%A3%B5%A1%F4 http://shike.gaotie.cn/zhan.asp?zhan=%A8%7D%CD%AD%B4%A8%B8%B4

再学IHanlder 类----------------关于Asp.net与iis原理网上看博客收获写一个验证码用一般处理程序记的好长时间前就写过不过现在再看有点不一样的感觉

建一个web网站 新建一般处理程序直接贴代码: using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.SessionState;using System.Drawing;using System.Text;using System.Drawing.Imaging; namespace HandlerStudy{    /// <summary>    /

Designing Evolvable Web API with ASP.NET 随便读,随便记 “The Internet,the World Wide Web,and HTTP”——HTTP

HTTP 我们将只聚焦在于与创建 Web APIs有关的部分. HTTP 是信息系统中的一个应用层协议,是Web的支柱. 其原先由 Berners-Lee, Roy Fielding 和 Henrik Frystyk Nielsen 三位计算机科学家们创作的.HTTP 为 客户端与服务器端之间跨网络相互传输信息定义了一个接口.它隐藏了双方的实现细 节. HTTP 设计用来戏剧性地改变系统,而容许一定程度上的延迟和数据的过时. 这种设计允许 计算机中间媒体,如代理服务器来协调通信,提供诸多好处,

Designing Evolvable Web API with ASP.NET 随便读,随便记 &ldquo;The Internet,the World Wide Web,and HTTP&rdquo;

1982年,诞生了 Internet; 1989年,诞生了World Wide Web . "World Wide Web"的构造为主要由 三部分构成: resources 资源 URIs 统一资源标识符 representations  呈现 其中,资源并不特指数据库之类的.任何东西可以是资源. URIs 分为两类: URLs 和URNs . URL 具有标识,并定位资源的功能. URN 则只是起标识作用. 通常讲,URI 默认指的是 URL. Google 建议,不要对实施了缓存的

ASP.NET Core 行军记 -----拔营启程

ASP.NET MVC 6:https://docs.asp.net/en/latest/mvc/index.html ASP.NET Core :https://docs.asp.net/en/latest/fundamentals/index.html cli-samples  : https://github.com/aspnet/cli-samples 以下是我在学习过程中的一些总结,作此记录 抱怨! 微软的发布候选版本真是坑爹…… 1:三月初开始看 ASP.NET Core ,利用 2