Click here to Skip to main content
16,016,580 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi dear's,
i design a page that have five RequiredFieldValidator and two button,
i want when click on btn_submit,RequiredFieldValidator 3 and 4 and 5 execute, and when click on btn2 RequiredFieldValidator 1 and 2 execute.
what i can must to do??
this is my code:
ASP.NET
    <br class="clear" />
    <ul class="service-ul">
        <li>
           <div id="opener">
            <a href="" class="service-ul-title"  önclick="return show();"> فرم ثبت نام </a></div>
              
          
            <div  id="benefits" style="display:none;">
                <table align="center" cellspacing="5px" class="tbl-inside-form">
                    <tr>
                        <td colspan="4">
                            الف: مشخصات فردی
                        </td>
                    </tr>
                    <tr>
                        <td>
                            نام و نام خانوادگی
                        </td>
                        <td>
                            <div class="frame-white-right">
                            </div>
                            <div class="frame-white-body form-txt-body">
                                <asp:TextBox ID="fname"  Text="" runat="server"></asp:TextBox>
                            </div>
                            <div class="frame-white-left">
                            </div>
                        </td>
                        <td>
                            نام پدر
                        </td>
                        <td>
                            <div class="frame-white-right">
                            </div>
                            <div class="frame-white-body form-txt-body">
                                <asp:TextBox ID="father_name"  Text="" runat="server"></asp:TextBox>
                            </div>
                            <div class="frame-white-left">
                            </div>
                        </td>
                    </tr>
                    <tr>
               
                        <td>
                            کد ملی
                        </td>
                        <td>
                            <div class="frame-white-right">
                            </div>
                            <div class="frame-white-body form-txt-body">
                                <asp:TextBox ID="national_code"  Text="" runat="server"></asp:TextBox>
                            </div>
                            <div class="frame-white-left">
                            </div>
                        </td>
                    </tr>
                  
                     <tr>
                       
                        <td>
                            ایمیل
                        </td>
                        <td>
                            <div class="frame-white-right">
                            </div>
                            <div class="frame-white-body form-txt-body">
                                <asp:TextBox ID="degree_of_academic_rank" Text="" runat="server"></asp:TextBox>
                            </div>
                            <div class="frame-white-left">
                            </div>
                        </td>
                    </tr>
                    <tr>
                        <td colspan="4">
                            وضعیت تحصیلی
                            <asp:RequiredFieldValidator ID="RequiredFieldValidator5" runat="server" 
                                ControlToValidate="fname" 
                                ErrorMessage="لطفا نام و نام خانوادگی را وارد نمایید." ForeColor="#CC0000" 
                                Display="Dynamic"></asp:RequiredFieldValidator>
                            <asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" 
                                ControlToValidate="degree_of_academic_rank" 
                                ErrorMessage="لطفا ایمیل خود را وارد نمایید." ForeColor="#CC0000" Display="Dynamic"></asp:RequiredFieldValidator>
                            <asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server" 
                                ControlToValidate="national_code" ErrorMessage="لطفا کدملی را وارد نمایید." 
                                ForeColor="#CC0000" Display="Dynamic"></asp:RequiredFieldValidator>
                        </td>
                    </tr>
                  
                    <tr>
                       
                       
                    </tr>
                    <tr>
                        <td colspan="4">
                            ج: وضعیت همکاری:
                        </td>
                    </tr>
                 
                    <tr>
                        <td colspan="4">
                            د: وضعیت همکاری با سایر شرکت ها
                        </td>
                    </tr>
                   
                    <tr>
                        <td colspan="4">
                           ه: مشخصات محل سکونت
                              <asp:RequiredFieldValidator ID="RequiredFieldValidator6" runat="server" 
                                ControlToValidate="address" Display="Dynamic" 
                                ErrorMessage="لطفا آدرس را وارد نمایید." ForeColor="#CC0000"></asp:RequiredFieldValidator>
                            <asp:RequiredFieldValidator ID="RequiredFieldValidator7" runat="server" 
                                ControlToValidate="mobile" Display="Dynamic" 
                                ErrorMessage="لطفا شماره همراه را وارد نمایید." ForeColor="#CC0000"></asp:RequiredFieldValidator>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            آدرس
                        </td>
                        <td colspan="3">
                            <div class="frame-white-right">
                            </div>
                            <div class="frame-white-body form-txt-body" style="width:547px">
                                <asp:TextBox ID="address" Text="" runat="server"  
                                style="width:547px"></asp:TextBox>
                            </div>
                            <div class="frame-white-left">
                            </div>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            تلفن همراه
                        </td>
                        <td colspan="3">
                            <div class="frame-white-right">
                            </div>
                            <div class="frame-white-body form-txt-body" >
                                <asp:TextBox ID="mobile" Text="" runat="server"></asp:TextBox>
                            </div>
                            <div class="frame-white-left">
                            </div>
                        </td>
                    </tr>
                   
                    
                    
                    
                    <tr>
            
                        <td colspan="4">
                            <div class="frame-btn-left">
                                        </div>
                                        <div class="frame-btn-body">
                                            <asp:Button ID="btn_submit" runat="server" Text="ثبت" 
                                                onclick="btn_submit_Click" />
                                        </div>
                                        <div class="frame-btn-right">
                                        </div>
                        </td>
                    </tr>
                </table>
            </div>
        </li>

        <li>
            <a href="" class="service-ul-title"  önclick="return hide();">
               پیگیری
            </a>
            <div id="upbutton" style="display:none;" >
                     <table align="center" cellspacing="5px" class="">
        <tr>
            
                
            <td class="">
                <div class="">
                </div>
                <div class="" dir="rtl">
                   
            کد ملی:  
                   
    <asp:TextBox ID="TxtMelliCode" runat="server"></asp:TextBox>
                </div>
                <br>
                 <div class="" style="direction: rtl">
                   
       کد رهگیری:  
                   
    <asp:TextBox ID="TxtId" runat="server"></asp:TextBox>
                  
                </div>
                 <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" 
                    ControlToValidate="TxtId" ErrorMessage="لطفا کد رهگیری را وارد نمایید." ForeColor="#CC0000"></asp:RequiredFieldValidator>
                    <br />
                <asp:RequiredFieldValidator  ID="RequiredFieldValidator2" runat="server" 
                    ControlToValidate="TxtMelliCode" Display="Dynamic" 
                    ErrorMessage="لطفا کد ملی را وارد نمایید." ForeColor="#CC0000"></asp:RequiredFieldValidator><br>
                    <asp:TextBox ID="TxtMessage" runat="server" Height="50px" TextMode="MultiLine" 
                    Visible="False" Width="227px"></asp:TextBox>
                               <div class="text-center" align="center">
                                
                              <asp:Button ID="BtnShow" runat="server" Text="نمایش" onclick="BtnShow_Click" CssClass="search-btn" Height="26px" Width="50px" />
                             
                              
                            </div>
                <div class="">
                </div>
            </td>
            
            <td width="100px" class="style1">
                <div class="">
                            </div>
                         
                            <div class="">
                            </div>
            </td>
        </tr>
         
        </table>
            </div>
        </li>
    </ul>
    </asp:Panel>
    <asp:Panel ID="pnl_ok" runat="server" Visible="false">
        پیام شما با موفقیت ثبت شد
        <br/>
        کد رهگیری: <asp:Label ID="lbl_id" runat="server" Text="Label"></asp:Label>
        
    </asp:Panel>
    
</asp:Content>
Posted

 
Share this answer
 
Make use of ValidationGroup. For example,for btn_submit and validators 3,4,5 assign same Validation Group[all with ValidationGroup="A"]. Do the same for btn2,validators 1 and 2[all with ValidationGroup="B"].See this link

ASP.NET ValidationGroup Property[^]

Regards..
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900