1.注意GroupName

<asp:RadioButton ID="rdoF" runat="server" Text="男" Checked="true"
GroupName="sex" />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <asp:RadioButton ID="rdoM"
runat="server" Text="女" GroupName="sex" />

2.SqlTransaction

conn = new SqlConnection(SqlConn);
SqlCommand cmd = new SqlCommand();
cmd.Connection = conn;
SqlTransaction tran = null;
//根据EmpID判断是否是修改操作还是新建操作
if (EmpID == "")
{
try
{
conn.Open();
//添加数据库事务
tran = conn.BeginTransaction();
// 绑定事务
cmd.Transaction = tran;

string strSqlText = "insert into dbo.Employee values('" + txtName.Text + "','" + rdoF.Checked + "','" + DateTime.Parse(txtBirth.Value) + "'," + int.Parse(ddlC.SelectedValue) + ",'" + txtAddress.Text + "','" + txtEmail.Text + "','" + txtRemark.Text + "')";
cmd.CommandText = strSqlText;
cmd.CommandType = CommandType.Text;
//提交人员注册的信息
int i = cmd.ExecuteNonQuery();
//获取新增的人员id
cmd.CommandText = "select E_Id from dbo.Employee where E_Name='" + txtName.Text + "' and E_Brith='" + txtBirth.Value + "' and E_Address='" + txtAddress.Text + "'";
SqlDataReader sr = cmd.ExecuteReader();
//新增的人员id
int E_ID = 0;
while (sr.Read())
{
E_ID = sr.GetInt32(0);
}
sr.Close();
//新增人员登录的账号和密码
cmd.CommandText = "insert into dbo.Emp_Submit values(" + E_ID + ",'" + txtAccount.Text + "','" + txtPwd1.Text + "')";
i += cmd.ExecuteNonQuery();
//提交事务
tran.Commit();
if (i > 1)
{
//成功后的提示信息
Response.Write("<script>alert('注册成功," + txtName.Text + "欢迎进入本站!')</script>");
txtNull();
lblNull();
}
else
{
Response.Write("<script>alert('注册失败!')</script>");
}
}
catch (Exception ex)
{
//回滚事务
tran.Rollback();
Response.Write("<script>alert('" + ex.Message + "')</script>");
}
finally
{
conn.Close();
}

3.

Ø在ASP.NET中,控件分成HTML服务控件和Web服务控件两种
Ø所有的 ASP.NET Web 服务器控件都派生自 System.Web.UI.WebControls 命名空间
Ø使用Web服务器控件需要注意AutoPostBack的使用
•HTML 服务器控件是由 ASP.NET 更新的标准 HTML 标签,通过添加 runat=“server” 属性将其用作服务器控件
HTML 服务器控件属于 System.Web.UI.HTMLControls 命名空间,派生自 HTMLControl 基类
 
4.浏览器向用户显示一个窗体,用户与该窗体进行交互,这导致该窗体回发到服务器

因为与服务器组件进行交互的所有处理必须在服务器上发生,这意味着对于要求处理的每一操作而言,必须将该窗体发送到服务器、进行处理、然后返回到浏览器。

5.

if((img.fileSize/1024)>500)
                            {
                                alert("你选择的第"+(i+1)+"个图片过大,必须在500kb以内!");return false;
                            }

6.批量上传

HttpFileCollection hfc = this.Request.Files;
for (int i = 0; i < hfc.Count; i++)
{
//Response.Write("<script>alert('" + hfc[i].FileName + "')</script>");
string fileUrl = hfc[i].FileName;
if (fileUrl == "")
{
continue;
}
//截取最后从双斜杠开始到结束的字符创(截取文件名称和后缀)
fileUrl = fileUrl.Substring(fileUrl.LastIndexOf("\\") + 1);
//服务器保存的路径
fileUrl = this.MapPath("userUpLoad\\") + fileUrl;
//小文件上传
hfc[i].SaveAs(fileUrl);
}
Response.Write("<script>alert('批量上传成功!')</script>");

7.

文本框不能为空验证

<tr>
<td class="style1">姓名:</td>
<td class="style1">
<asp:TextBox ID="txtName" runat="server"></asp:TextBox>
</td>
<td class="style1">
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"
ControlToValidate="txtName" ErrorMessage="姓名不能为空" Display="None"></asp:RequiredFieldValidator>
</td>
</tr>

比较验证,比如密码

<tr>
<td>密码:</td>
<td>
<asp:TextBox ID="txtPwd1" runat="server" TextMode="Password"></asp:TextBox>
</td>
<td></td>
</tr>
<tr>
<td>确认密码:</td>
<td>
<asp:TextBox ID="txtPwd2" runat="server" TextMode="Password"></asp:TextBox>
</td>
<td>
<asp:CompareValidator ID="CompareValidator1" runat="server"
ControlToCompare="txtPwd1" ControlToValidate="txtPwd2"
ErrorMessage="密码与确认密码不一致!"></asp:CompareValidator>
</td>
</tr>

出生日期不得低于某个固定日期

<tr>
<td class="style1">出生日期:</td>
<td class="style1">
<asp:TextBox ID="txtBirth" runat="server"></asp:TextBox>
</td>
<td class="style1">
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server"
ControlToValidate="txtBirth" Display="None" ErrorMessage="出生日期不能为空!"></asp:RequiredFieldValidator>
<asp:CompareValidator ID="CompareValidator2" runat="server"
ControlToValidate="txtBirth" ErrorMessage="出生日期不匹配!" Operator="LessThanEqual"
Type="Date" ValueToCompare="2012-11-15"></asp:CompareValidator>
</td>
</tr>

输入的必须是整数

<tr>
<td>工作年限:</td>
<td>
<asp:TextBox ID="TextBox2" runat="server">0</asp:TextBox>
</td>
<td>
<asp:CompareValidator ID="CompareValidator3" runat="server"
ControlToValidate="TextBox2" ErrorMessage="输入的值必须是数字" Operator="DataTypeCheck"
Type="Integer"></asp:CompareValidator>
</td>
</tr>

数值必须处于某个范围内

<tr>
<td class="style1">账号:</td>
<td class="style1">
<asp:TextBox ID="txtAccount" runat="server"></asp:TextBox>
</td>
<td class="style1">
<asp:RangeValidator ID="RangeValidator1" runat="server"
ControlToValidate="txtAccount" ErrorMessage="必须是在1000到10000之间的数字"
MaximumValue="10000" MinimumValue="1000" Type="Integer"></asp:RangeValidator>
</td></tr>

验证电子邮箱的格式是否正确

<tr>
<td class="style1">电子邮件:</td>
<td class="style1">
<asp:TextBox ID="txtEmail" runat="server"></asp:TextBox>
</td>
<td class="style1">
<asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server"
ControlToValidate="txtEmail" ErrorMessage="电子邮件的值不匹配!"
ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"></asp:RegularExpressionValidator>
</td>
</tr>

该控件收集本页的所有验证错误信息,并可以将它们组织以后再显示出来

<tr>
<td colspan="2">
<asp:ValidationSummary ID="ValidationSummary1" runat="server"
DisplayMode="List" />
</td>
<td>&nbsp;</td>
</tr>

CustomValidator(自定义验证)控件

<td>
<asp:CustomValidator ID="CustomValidator1" runat="server"
ControlToValidate="TextBox3" ErrorMessage="验证码不正确!"
onservervalidate="CustomValidator1_ServerValidate"></asp:CustomValidator>
</td>

protected void CustomValidator1_ServerValidate(object source, ServerValidateEventArgs args)
{
if (TextBox3.Text == "1234")
{
args.IsValid = true;
}
else
{
args.IsValid = false;
}
}

args.IsValid 为ture则不报错,若false则报ErrorMessage="验证码不正确!"

验证控件请参考 http://www.51cto.com/specbook/14/3305.htm

aspx小集合的更多相关文章

  1. 【转】HTML5的小知识点小集合

    html5的小知识点小集合 html5知识   1.  Doctype作用?标准模式与兼容模式各有什么区别? (1).<!DOCTYPE>声明位于位于HTML文档中的第一行,处于<h ...

  2. html5的小知识点小集合

      html5的小知识点小集合 html5知识   1.  Doctype作用?标准模式与兼容模式各有什么区别? (1).<!DOCTYPE>声明位于位于HTML文档中的第一行,处于< ...

  3. Ubuntu常用软件安装(小集合)

    跨平台系列汇总:http://www.cnblogs.com/dunitian/p/4822808.html#linux Linux包系列的知识:https://www.cnblogs.com/dun ...

  4. Java-大集合拆分为指定大小的小集合

    因为Oracle数据的in 最大允许1000 ,超过就会报错, 所以需要将集合拆分为多个集合进行处理. /** * 拆分集合 * @param <T> * @param resList 要 ...

  5. 我为Net狂 ~ 社交平台系列小集合!

    微信平台: 我为Net狂(dotNetCrazy) 资源贴吧: http://tieba.baidu.com/f?kw=毒逆天 个人博客: http://dunitian.cnblogs.com/ h ...

  6. SVN代码冲突解决方案小集合

    对于刚接触svn的人来说,svn冲突后,不能提交是件让人很郁闷的事情.最让人郁闷的事,是代码间的覆盖.你把我代码盖了,我会很火大的.谁把谁的盖了都不爽. 为什么会出现代码冲突问题呢,因为不同的人,同时 ...

  7. Mysql监控工具小集合

    介绍一些常见的Mysql监控工具. Cacti Cacti是 一套基于PHP,MySQL,SNMP及RRDTool开发的网络流量监测图形分析工具.它通过snmpget来获取数据,使用 RRDtool绘 ...

  8. NSStirng、NSArray、以及枚举(Method小集合)

    Object-c代码 /**************************************************************************************** ...

  9. 佩特来项目经验小集合(2)___组合查询存储过程,报错 &quot;varchar JBID=&#39;&#39; 转换成数据类型 int 时失败&quot;

       今天写一个组合查询的存储过程遇到这样一个问题:在将 varchar 值 'SELECT * FROM View_DLS_WXJD_Customer WHERE 1=1 and JBID ='' ...

随机推荐

  1. Android网络开发之HttpURLConnection

    http是一个可靠的传输,建立在TCP/IP连接之上,缺省端口是80,其他端口号也可以用.Android可以用HttpURLConnection或HttpClient接口来开发http程序. http ...

  2. PHP扩展的基本结构

    1.下载php源码 git clone https://github.com/php/php-src.git  2,创建扩展 cd php-src/ext/ ./ext_skel --extname= ...

  3. C#编写的 8种初级+高级排序方法(转)

    摘自:http://blog.csdn.net/mevin/article/details/6714520 程序代码: view plaincopy to clipboard using System ...

  4. 面试题 Comparable、Comparator 比较

    Comparable 用作默认的比较方式 Comparator 用作自定义的比较方式,当默认的比较方式不适用时或者没有提供默认的比较方式,使用Comparator就非常有用. 像Arrays和Coll ...

  5. servlet与filter的url-pattern设置方式

    servlet与filter的url-pattern设置方式: 1.精确匹配: /directory/file1.jsp /directory/file2.jsp /directory/file3.j ...

  6. JMeter学习笔记--JMeter属性和变量

    JMeter属性统一定义在jmeter.properties文件中.JMeter属性在测试脚本的任何地方都是可见的(全局),通常被用来定义一些JMeter使用的默认值.如属性remote_hosts定 ...

  7. OAF_OAF控件系列2 - LOV的实现(案例)

    2014-06-02 Created By BaoXinjian

  8. Unix环境高级编程(十五)高级I/O

    1.非阻塞I/O 对低速设备的I/O操作可能会使进程永久阻塞,这类系统调用主要有如下情况:(1)如果数据并不存在,则读文件可能会使调用者永远阻塞(例如读管道.终端设备和网络设备).(2)如果数据不能立 ...

  9. OC 中new与alloc/init的差别

    英文具体解释:http://macresearch.org/difference-between-alloc-init-and-new 1.在实际开发中非常少会用到new.一般创建对象咱们看到的全是[ ...

  10. EC20 minipcie版4g模块开发笔记

    插在电脑上实验时若出现 AT+CREG? +CREG: 0,2 可能是usb口供电不足所致,换至主机箱后面usb口后问题解决,返回值+CREG: 0,1