2015-12-11 62 views
1

我有上有3個文本框字段,其中我使用
ASP一個div:使用RequiredFieldValidator和ASP:在更改密碼按鈕CompareValidator股利不會不可見時可見設置爲false按鈕clcik

點擊div變得可見

protected void btnPass_Click(object sender, EventArgs e) 
    { 
     chngPwd.Visible = true; 
    } 

並在按鈕上取消可視屬性設置爲false但它不會隱形。

protected void btnCancel_Click(object sender, EventArgs e) 
    { 
     chngPwd.Visible = false; 
    } 

This is my page showing the error on cancel button press.

ASP代碼如下

<div runat="server" id="chngPwd" visible="false" style="margin-left: 40px"> 
     <div> 
      <div class="col-md-4"></div> 
      <div class="col-md-8"> 
       <asp:Label ID="lblOldP" runat="server" Text="Old Password: -"></asp:Label> 
       &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
      <asp:TextBox ID="txtOldP" runat="server" TextMode="Password" Width="149" Height="33px"></asp:TextBox> 
      </div> 
      <br /> 
      <br /> 
     </div> 
     <div> 
      <div class="col-md-4"></div> 
      <div class="col-md-8"> 
       <asp:RequiredFieldValidator runat="server" ControlToValidate="txtOldP" CssClass="text-danger" ErrorMessage="The Old Password field is required." /> 
       <br /> 
      </div> 
     </div> 
     <br /> 

     <div> 
      <div class="col-md-4"></div> 
      <div class="col-md-8"> 
       <asp:Label ID="lblNewP" runat="server" Text="New Password: -"></asp:Label> 
       &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
      <asp:TextBox ID="txtNewP" runat="server" TextMode="Password" Width="149" Height="33px"></asp:TextBox> 
      </div> 
      <br /> 
      <br /> 
     </div> 
     <div> 
      <div class="col-md-4"></div> 
      <div class="col-md-8"> 
       <asp:RequiredFieldValidator runat="server" ControlToValidate="txtNewP" CssClass="text-danger" ErrorMessage="The New Password field is required." /> 
       <br /> 
      </div> 
     </div> 
     <br /> 
     <div> 
      <div class="col-md-4"></div> 
      <div class="col-md-8"> 
       <asp:Label ID="lblRNewP" runat="server" Text="Confirm New Password: -"></asp:Label>&nbsp;&nbsp; 
      <asp:TextBox ID="txtRNewP" runat="server" TextMode="Password" Width="149" Height="33px"></asp:TextBox> 
      </div> 
      <br /> 
      <br /> 
     </div> 
     <div> 
      <div class="col-md-4"></div> 
      <div class="col-md-8"> 
       <asp:RequiredFieldValidator runat="server" ControlToValidate="txtRNewP" CssClass="text-danger" ErrorMessage="The Confirm New Password field is required." /> 
       <br /> 
       <asp:CompareValidator runat="server" ControlToCompare="txtNewP" ControlToValidate="txtRNewP" CssClass="text-danger" ErrorMessage="The Password doesn't match." /> 
       <br /> 
      </div> 
     </div> 
     <br /> 
     <div> 
      <div class="col-md-8"></div> 
      <div class="col-md-4"> 
       <asp:Button ID="btnSbmt" runat="server" Text="Submit" OnClick="btnChngP_Click" /> 
       <asp:Button ID="btnCancel" runat="server" Text="Cancel" OnClick="btnCancel_Click" /> 
      </div> 
     </div> 
     <br /> 
     <br /> 

<div> 
+0

我們可以看到你使用 – KratosMafia

+0

加在我的問題本身的ASP代碼的ASP。請。 –

+0

以及你的最後一個div應該是/ div – KratosMafia

回答

3

所以在這裏你的問題是預期的驗證正在工作。 btnclick正在關閉,但沒有打電話,因爲你有一個驗證器。如果你輸入的信息,然後點擊取消div將隱藏。但是你已經設置爲不運行任何東西,除非這些文本框被填充。

因此,我們將改變這一

<asp:Button ID="btnCancel" runat="server" Text="Cancel" OnClick="btnCancel_Click" /> 

這個

<asp:Button ID="btnCancel" runat="server" Text="Cancel" OnClick="btnCancel_Click" CausesValidation="false"/> 
+0

我該如何做這個驗證只提交按鈕點擊。當我clcik取消它無關緊要的文本框是空的還是空的。 –

+0

剛把它貼出來 – KratosMafia

+0

希望能幫到你。 – KratosMafia

相關問題