当前位置:编程学习 > asp >>

asp.net开发常用代码

  //Repeater项绑定事件
  protected void rptCategory_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item)
            {
           }
        }

//弹出
Page.ClientScript.RegisterStartupScript(Page.ClientScript.GetType(), "myscript", "alert('用户没有权限!');", true);

//ajax弹出
ScriptManager.RegisterClientScriptBlock(upCatalog, typeof(UpdatePanel), "myscript", "alert('请填写编号!');", true);


//确认框
OnClientClick="return confirm('确认要删除此收货地址吗?')"

//Email验证

<asp:RegularExpressionValidator ID="refUserNameOrEmail" runat="server"    ControlToValidate="UserName" Display="Dynamic" ErrorMessage="Invalid email" ToolTip="Invalid email"  ValidationExpression="[\w\.-]+(\+[\w-]*)?@([\w-]+\.)+[\w-]+"
                                                    ValidationGroup="CreateUserForm">E-mail格式不正确</asp:RegularExpressionValidator>


//只能输数字
<asp:TextBox runat="server" ID="txtMobileNumber" CssClass="adminInput" onkeyup="value=value.replace(/[^\d]/g,'');"   onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\d]/g,''))"> </asp:TextBox>

//只能输中文
<asp:TextBox ID="txtLastName" runat="server" MaxLength="40" onkeyup="value=value.replace(/[^\u4E00-\u9FA5]/g,'')"   onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\u4E00-\u9FA5]/g,''))"></asp:TextBox>


//手机验证
 <asp:RegularExpressionValidator runat="server" ID="RegularExpressionValidator1" Display="Dynamic" ControlToValidate="txtMobileNumber" ErrorMessage='例如:13854674256'
               ToolTip='Invalid email' ValidationGroup="CustomerInfo" ValidationExpression="^(((\(\d{3}\))|(\d{3}\-))?13[0-9]\d{8}|15[0-9]\d{8}|18[0-9]\d{8})"> </asp:RegularExpressionValidator>

添加序列号
<%# Container.ItemIndex + 1%>
<%# Container.DataItemIndex+1 %>


 作者“libt的专栏libt”

补充:Web开发 , ASP.Net ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,