2014-06-20 16 views
0

我想,按鈕單擊它首先檢查驗證,然後打印命令在此執行 後,我的ASPX代碼:打印頁面查看驗證

<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" Runat="Server"> 
<style type="text/css"> 
    .style1 
    { 
    } 

    @media print 
    { 
     .header, .style1, .footer,.hide 
     { 
      display:none 
     } 
    } 
</style> 
</asp:Content> 
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" Runat="Server"> 
    <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> 
    <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="TextBox1" 
     ErrorMessage="RequiredFieldValidator" style="color: #FF0000"></asp:RequiredFieldValidator> 
    <br /> 
    <asp:Button ID="Button1" runat="server" Text="Button" OnClientClick="window.print();" /> 
</asp:Content> 

問題是,當我在按鈕點擊執行打印功能並且不檢查驗證器。

回答

0

JavaScript OnClientClick將在您的頁面驗證之前觸發。打印之前,您可以嘗試驗證頁面。

function Validate() { 
    if(Page_ClientValidate()) 
     window.print(); 
} 

然後像這樣調用它。

<asp:Button ID="Button1" runat="server" Text="Button" OnClientClick="Validate();" /> 
0

設置的CausesValidation屬性按鈕來真的!