打开手风琴面板验证错误(Asp.net)

时间:2017-05-26 09:12:13

标签: jquery asp.net

当我点击提交时,表单会正确验证。 它显示在第一个选项卡中输入的所有信息,如果您手动单击第二个或第三个选项卡,它会在第二个和第三个选项卡的输入框旁边显示验证错误消息。

我希望它能够通过第一个验证错误实例激活选项卡,以便用户知道他们错过了什么。即,在上面的示例中,第二个选项卡在单击提交时打开。

我希望在文本框未验证时打开哪个标签或标签会出错。

我使用jquery-ui-1.8.16.custom.min.js。 我尝试添加以下内容:



<script type="text/javascript">
                $(function () {
                    $("#accordion").accordion({ autoHeight: false });
                });

            
            </script>
            <div id="accordion">
                <h3>
                    <a href="#">Kişisel Bilgiler</a></h3>
                <div id="dvKisisel">
                    <div class="radsatir">
                        <div class="radw360">
                            <div class="radw120 radleft">
                                Adınız</div>
                            <div class="radw200 radright">
                                <asp:TextBox ID="txtAd" Width="180" runat="server"></asp:TextBox>
                                <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="txtAd" ErrorMessage="&nbsp;&nbsp;Adınızı Giriniz!" SetFocusOnError="True" Display="Dynamic" ValidationGroup="odeme"></asp:RequiredFieldValidator>
                            </div>
                          
                        </div>
                    </div>
                    <div class="radsatir">
                        <div class="radw360">
                            <div class="radw120 radleft">
                                Soyadınız</div>
                            <div class="radw200 radright">
                                <asp:TextBox ID="txtSoyad" Width="180" runat="server"></asp:TextBox>
                                <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="txtSoyad" ErrorMessage="&amp;nbsp;&amp;nbsp;Soyadınızı Giriniz!" SetFocusOnError="True" Display="Dynamic" ValidationGroup="odeme"></asp:RequiredFieldValidator>
                            </div>
                        </div>
                    </div>
                    <div class="radsatir">
                        <div class="radw360">
                            <div class="radw120 radleft">
                                Email</div>
                            <div class="radw200 radright">
                                <asp:TextBox ID="txtEmail" Width="180" runat="server"></asp:TextBox>
                                <asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" ControlToValidate="txtEmail" ErrorMessage="&amp;nbsp;&amp;nbsp;Email Adresinizi Giriniz!" SetFocusOnError="True" Display="Dynamic" ValidationGroup="odeme"></asp:RequiredFieldValidator>
                                <asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ControlToValidate="txtEmail" ErrorMessage="&amp;nbsp;&amp;nbsp;Geçerli Mail Giriniz!" SetFocusOnError="True" ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*" Display="Dynamic" ValidationGroup="odeme"></asp:RegularExpressionValidator> 
                                <asp:CustomValidator ID="cvEmail" runat="server" ControlToValidate="txtEmail" 
                        ErrorMessage="Bu mail adresi zaten kayıtlı!" onservervalidate="cvEmail_ServerValidate" 
                        ValidationGroup="odeme" Display="Dynamic"></asp:CustomValidator>
                            </div> 
                        </div>
                    </div>
                    <div class="radsatir">
                        <div class="radw360">
                            <div class="radw120 radleft">
                                Cep Telefonu</div>
                            <div class="radw200 radright">
                                <asp:TextBox ID="txtCepTelefonu" Width="180" runat="server"></asp:TextBox>
                                <asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server" ControlToValidate="txtCepTelefonu" ErrorMessage="&amp;nbsp;&amp;nbsp;Cep Telefonunuzu Giriniz!" SetFocusOnError="True" Display="Dynamic" ValidationGroup="odeme"></asp:RequiredFieldValidator>
                                <asp:RegularExpressionValidator ID="RegularExpressionValidator2" runat="server" ControlToValidate="txtCepTelefonu" ErrorMessage="&amp;nbsp;&amp;nbsp;Geçerli Cep Numarası Giriniz!&amp;nbsp;&amp;nbsp;(Örn:555-555-55-55)" ValidationExpression="^\d{3}-\d{3}-\d{2}-\d{2}$" Display="Dynamic" ValidationGroup="odeme"></asp:RegularExpressionValidator>
                            </div>
                        </div>
                    </div>
                </div>
                <h3>
                    <a href="#">Fatura Bilgileri</a></h3>
                <div>
                    <div class="radsatir">
                        <div class="radw360">
                            <div class="radw120 radleft">
                                Fatura Adı</div>
                            <div class="radw200 radright">
                                <asp:TextBox ID="txtFaturaAdi" Width="180" runat="server"></asp:TextBox>
                                <asp:RequiredFieldValidator ID="RequiredFieldValidator5" runat="server" ControlToValidate="txtFaturaAdi" ErrorMessage="&amp;nbsp;&amp;nbsp;Fatura Adını Yazınız!" SetFocusOnError="True" Display="Dynamic" ValidationGroup="odeme"></asp:RequiredFieldValidator>
                            </div>
                        </div>
                    </div>
                    <div class="radsatir">
                        <div class="radw360">
                            <div class="radw120 radleft">
                                Fatura TC Kimlik No / Vergi No</div>
                            <div class="radw200 radright">
                                <asp:TextBox ID="txtFaturaVergiNo" Width="180" runat="server"></asp:TextBox>
                                <asp:RequiredFieldValidator ID="RequiredFieldValidator6" runat="server" ControlToValidate="txtFaturaVergiNo" ErrorMessage="&amp;nbsp;&amp;nbsp;TC Kimlik No/Vergi No Giriniz!" SetFocusOnError="True" Display="Dynamic" ValidationGroup="odeme"></asp:RequiredFieldValidator>
                                <asp:RegularExpressionValidator ID="RegularExpressionValidator3" runat="server" ControlToValidate="txtFaturaVergiNo" ErrorMessage="&amp;nbsp;&amp;nbsp;Hatalı Giriş!" ValidationExpression="([0-9])+" Display="Dynamic" ValidationGroup="odeme"></asp:RegularExpressionValidator>
                            </div>
                        </div>
                    </div>
<div class="radsatir">
            <asp:Button CssClass="greenbutton" ID="btnSiparisTamamla" runat="server" Text="Siparişi Tamamla"
                OnClick="btnSiparisTamamla_Click" ValidationGroup="odeme" />
        </div>
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:0)

在标签更改上调用常用验证功能,请参阅以下编码模板:

<div id="tab1">
   Tab 1
</div>
<div id="tab2">
   Tab 2
</div>
<div id="tab3">
   Tab 3
</div>

function validation(){
//validation code here return true if everything is good and false if some thing is wrong
}

$("#tab1").click(function(){
   if(validation()){
      return true;
   }else{
      return false;
   }
});
$("#tab2").click(function(){
   if(validation()){
      return true;
   }else{
      return false;
   }
});
$("#tab3").click(function(){
   if(validation()){
      return true;
   }else{
      return false;
   }
});