Bypase验证控件 [英] Bypase the validation controls

查看:73
本文介绍了Bypase验证控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的Asp.net WebForm中,我有一个链接按钮lnk_add如果用户点击它,那么他将显示一个asp.net表,其中包含用于输入车辆详细信息的控件,其中有五个或六个验证控件表....他可以输入车辆细节并保存,但如果他再次单击链接按钮,则表格不可见

我设法在首先单击链接按钮时使表格可见。但是当他再次点击它时,表格不会变得不可见。可能是因为触发了validatoion控件。

我的要求是当linkBut​​ton被点击时使表格不可见(当linkbutton文本为取消时)



In my Asp.net WebForm I had a link button "lnk_add" If the user click on it then he will be displayed with a asp.net table containing controls to input Vehicle details , There are five or six validation controls within that table.... He can enter the vehicle detail and save but if he again click the the link button the table is made invisible
I managed to make the table visible when he click the Link Button first.But when he click it again the table is not becoming invisible..may be because the validatoion controls are triggered.
Simply my requirement is to make the table invisible when linkButton clicked (when linkbutton text is "cancel")

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
        
            <asp:LinkButton ID="lnk_Add" runat="server" onclick="lnk_Add_Click">Add New</asp:LinkButton>
      
    <table class="style1" bgcolor="#FF9966" id="tblAddnew"  runat="server">
    <tr>
        <td class="style26">
            Manufacturer :</td>
        <td class="style7">
            <asp:TextBox ID="txtmanufacturer" runat="server"></asp:TextBox>
            <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" 

        ControlToValidate="txtmanufacturer" ErrorMessage="Manufacturer name required">*</asp:RequiredFieldValidator>
        </td>
        <td class="style18">
            Model :</td>
        <td class="style29">
            <asp:TextBox ID="txtmodel" runat="server"></asp:TextBox>
    <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" 

        ControlToValidate="txtmodel" ErrorMessage="Model Num required" 

                SetFocusOnError="True">*</asp:RequiredFieldValidator>
        </td>
        <td class="style6">
            Type</td>
        <td class="style9">
            <asp:DropDownList ID="cmb_type" runat="server" Height="21px" Width="145px">
                <asp:ListItem>3 Tone Truck</asp:ListItem>
                <asp:ListItem>5 Tone Truck</asp:ListItem>
                <asp:ListItem>10Tone Truck</asp:ListItem>
                <asp:ListItem>Car</asp:ListItem>
                <asp:ListItem>13 Seater Bus</asp:ListItem>
                <asp:ListItem>Pick Up</asp:ListItem>
                <asp:ListItem>50 Seater</asp:ListItem>
            </asp:DropDownList>
        </td>
    </tr>
    <tr>
        <td class="style27">
            Engine Number</td>
        <td class="style11">
            <asp:TextBox ID="txtenginenum" runat="server"></asp:TextBox>
    <asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" 

        ControlToValidate="txtenginenum" ErrorMessage="Engine num Required" 

                ForeColor="Red" SetFocusOnError="True">*</asp:RequiredFieldValidator>
        </td>
        <td class="style19">
            Vehicle Number :</td>
        <td class="style30">
            <asp:TextBox ID="txtvehiclenum" runat="server"></asp:TextBox>
        </td>
        <td class="style14">
            Registeration Date :</td>
        <td class="style15">
            </td>
    </tr>
    <tr>
        <td class="style28">
            Registered from Date :</td>
        <td class="style21">
            <asp:TextBox ID="txt_fromdate" runat="server"></asp:TextBox>
    <asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server" 

        ControlToValidate="txt_fromdate" ErrorMessage="Registration From Date Required">*</asp:RequiredFieldValidator>
    <asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" 

        ControlToValidate="txt_fromdate" 

        ErrorMessage="Enter Correct from date (dd/mm/yyy)" 

        

                ValidationExpression="(0[1-9]|[12][0-9]|3[01])[- /.](0[1-9]|1[012])[- /.](19|20)[0-9]{2}" 

                ForeColor="#FF3300" SetFocusOnError="True">*</asp:RegularExpressionValidator>
        </td>
        <td class="style22">
            Registered to Date :</td>
        <td class="style31">
            <asp:TextBox ID="txt_todate" runat="server"></asp:TextBox>
    <asp:RegularExpressionValidator ID="RegularExpressionValidator2" runat="server" 

        ControlToValidate="txt_todate" ErrorMessage="Enter Correct to date (dd/mm/yyy)" 

        

                ValidationExpression="(0[1-9]|[12][0-9]|3[01])[- /.](0[1-9]|1[012])[- /.](19|20)[0-9]{2}" 

                SetFocusOnError="True">*</asp:RegularExpressionValidator>
    <asp:RequiredFieldValidator ID="RequiredFieldValidator5" runat="server" 

        ControlToValidate="txt_todate" ErrorMessage="To Date Required" 

                SetFocusOnError="True">*</asp:RequiredFieldValidator>
        </td>
        <td class="style24">
            </td>
        <td class="style25">
            </td>
    </tr>
    <tr>
        <td class="style26">
            Driver Code :</td>
        <td class="style7">
            <asp:DropDownList ID="cmb_driverCode" runat="server" Height="22px" 

                Width="131px">
            </asp:DropDownList>
        </td>
        <td class="style18">
             </td>
        <td class="style29">
             </td>
        <td class="style6">
             </td>
        <td class="style9">
             </td>
    </tr>
    <tr>
        <td class="style26">
             </td>
        <td class="style7">
             </td>
        <td class="style18">
            <asp:Button ID="Btn_save0" runat="server" Text="Save" Width="90px" 

                onclick="Btn_save0_Click" />
        </td>
        <td class="style29">
            <asp:Button ID="Btn_save" runat="server" Text="Cancel" Width="90px" />
        </td>
        <td class="style6">
             </td>
        <td class="style9">
             </td>
    </tr>
    <tr>
        <td class="style26" bgcolor="#FFFFCC">
    <asp:ValidationSummary ID="ValidationSummary1" runat="server" 

        ForeColor="#FF3300" /></td>
        <td class="style7">
          
          </td>
        <td class="style18">
             </td>
        <td class="style29">
           
        </td>
        <td class="style6">
             </td>
        <td class="style9">
             </td>
    </tr>
</table>
   
</asp:Content>







My code behind is




My code behind is

public partial class VehicleRegistrationForm : System.Web.UI.Page
  {
      protected void Page_Load(object sender, EventArgs e)
      {
          if (!IsPostBack)
          {
              tblAddnew.Visible = false;

          }
      }

      protected void lnk_Add_Click(object sender, EventArgs e)
      {
          if (lnk_Add.Text != "Cancel")
          {
              tblAddnew.Visible = true;
              lnk_Add.Text = "Cancel";
             // Driverjobcodeload();
          }
          else
          {
              tblAddnew.Visible = false;
              lnk_Add.Text = "Add New";
          }
      }

      protected void Btn_save0_Click(object sender, EventArgs e)
      {

      }
  }





<



<

推荐答案

Set CauseValidation=\"false\" of the link button control.
Set CauseValidation="false" of the link button control.


这篇关于Bypase验证控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆