zoukankan      html  css  js  c++  java
  • RequiredFieldValidator的使用

    特別說明:1.一個Button要對頁面的多個控件進行驗證,則需要設置button和其它受控控件的ValidationGroup屬性

    aspx頁面實例:

      <tr class="h">
                                <td class="tdr">
                                    起始日:
                                </td>
                                <td class="tdl">
                                    <asp:TextBox ID="tb_fromdate" runat="server" CssClass="AlignLeftBc" ValidationGroup="SaveInsert"></asp:TextBox>
                                    <ccl:CalendarExtender ID="tb_fromdate_CalendarExtender" runat="server" Format="yyyy/MM/dd HH:mm:ss"
                                        TargetControlID="tb_fromdate">
                                    </ccl:CalendarExtender>
                                    <asp:RequiredFieldValidator ID="Rfvfrom" runat="server" ControlToValidate="tb_fromdate"
                                        ErrorMessage="不能為空!" ValidationGroup="SaveInsert">*</asp:RequiredFieldValidator>
                                </td>
                            </tr>
                            <tr class="h">
                                <td class="tdr">
                                    截止日:
                                </td>
                                <td class="tdl">
                                    <asp:TextBox ID="tb_todate" runat="server" CssClass="AlignLeftBc" ValidationGroup="SaveInsert"></asp:TextBox>
                                    <ccl:CalendarExtender ID="tb_todate_CalendarExtender" runat="server" Format="yyyy/MM/dd HH:mm:ss"
                                        TargetControlID="tb_todate">
                                    </ccl:CalendarExtender>
                                    <asp:RequiredFieldValidator ID="Rfvto" runat="server" ControlToValidate="tb_todate"
                                        ErrorMessage="不能為空!" ValidationGroup="SaveInsert">*</asp:RequiredFieldValidator>
                                </td>
                            </tr>
                            <tr style="height: 30px">
                                <td align="center" colspan="2" valign="middle">
                                    <asp:LinkButton ID="lbt_Sure" runat="server" Font-Underline="false" OnClick="lbt_Sure_Click"
                                        ValidationGroup="SaveInsert" OnClientClick="return ConfirmMe()">
                <img alt="保存" src="../../../images/Save01.gif" style=" border:none" />
                                    </asp:LinkButton>
                                    &nbsp;&nbsp;
                                    <asp:LinkButton ID="lbt_close" runat="server" Font-Underline="false" OnClick="lbt_close_Click">
                <img alt="關閉" src="../../../images/Cancel01e.gif" style=" border:None" />
                                    </asp:LinkButton>
                                </td>
                            </tr>

    後台代碼:

     protected void lbt_Sure_Click( object sender, EventArgs e)
        {
            if (!!Page.IsValid)
            {

     //通過Page.IsValid來取得頁面是否通過驗證

    }

    }

    多一分冷靜,少一分浮躁
  • 相关阅读:
    QuantLib 金融计算——基本组件之 Date 类
    挑选合适的机器学习资料
    【翻译】理解 LSTM 及其图示
    《信任的速度》读后感
    Git分支使用心得
    c# 多线程 创建对象实例
    c# 设计模式之单例模式
    C# 设计模式之空对象模式
    c# 静态构造函数与构造函数的调用先后
    C# 中关于接口实现、显示实现接口以及继承
  • 原文地址:https://www.cnblogs.com/AnnyGird-LiMing/p/4955652.html
Copyright © 2011-2022 走看看