Click here to Skip to main content
15,885,985 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.NET
<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
C#
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)
      {

      }
  }


<
Posted

1 solution

Set CauseValidation="false" of the link button control.
 
Share this answer
 

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