2011-01-19 6 views
0

私は検証を実行したいアップフィールドバリデータ火災は望ましくない

<%@ Page Title="" Language="C#" MasterPageFile="~/CaseAdmin.master" AutoEventWireup="true" CodeBehind="AddExhibit.aspx.cs" Inherits="Prototype5.AddExhibit" %> 

<h2 class="style2"> 
    <strong><span style="color: #FFFFFF">Add Exhibit 
    Form</span></strong></h2> 
<div style="width: 600px"> 
<table style="width: 303px" align="left"> 
     <tr> 
      <td class="style26" style="background-color: #666666"> 
       <p class="style5" style="color: #000000; background-color: #666666;"> 
        <strong style="background-color: #666666">Select Existing Case ID:  
       </strong>  
       </p></td> 
      <td class="" style="background-color: #C0C0C0" align="left"> 
       <asp:DropDownList ID="DropDownListcaseid" runat="server" 
        onselectedindexchanged="DropDownListcaseid_SelectedIndexChanged"> 
       </asp:DropDownList> 
       <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" 
        ControlToValidate="DropDownListcaseid" 
        ErrorMessage="Please select a valid case id from the dropdown menu" 
        ForeColor="Red">*</asp:RequiredFieldValidator> 
      </td> 
     </tr> 
     <tr> 
      <td class="style4" colspan="2"> 
       &nbsp;</td> 
     </tr> 
    </table> 

    <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
     ConnectionString="<%$ ConnectionStrings:CMSSQL3ConnectionString1 %>" 
     SelectCommand="SELECT [CaseID] FROM [Cases]"></asp:SqlDataSource> 

</div> 
<div style="width: 603px; height: 75px; "> 

    <table style="height: 66px; width: 598px; top: 277px; left: 268px;" 
     align="left"> 
     <tr> 
      <td class="bold" 
       style="color: #000000; background-color: #666666; width: 127px;"> 
       <strong>Exhibit Type</strong></td> 
      <td class="bold" style="background-color: #666666; width: 228px;"> 
       <span style="color: #000000">Exhibit Image</td> 
      <td class="bold" style="background-color: #666666; width: 111px;"> 
       <span style="color: #000000">Stored Location</span></td> 
      <td class="bold" style="background-color: #666666; color: #000000;"> 
       Officer ID</span></td> 
     </tr> 
     <tr> 
      <td class="style32" style="background-color: #C0C0C0; width: 127px;"> 
       <asp:DropDownList ID="exhibitTypeDropDownList" runat="server"> 
        <asp:ListItem></asp:ListItem> 
        <asp:ListItem>Hard Disk</asp:ListItem> 
        <asp:ListItem>Pen Drive</asp:ListItem> 
        <asp:ListItem>Laptop</asp:ListItem> 
        <asp:ListItem>Palm Devce</asp:ListItem> 
        <asp:ListItem>Mobile Phone</asp:ListItem> 
        <asp:ListItem>Tablet PC</asp:ListItem> 
        <asp:ListItem>Pager</asp:ListItem> 
       </asp:DropDownList> 
       <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" 
        ControlToValidate="exhibitTypeDropDownList" 
        ErrorMessage="Please Enter the type of exhibit. eg. Harddisk" 
        ForeColor="Red" ondisposed="addExhibitButton_Click">*</asp:RequiredFieldValidator> 
      </td> 
      <td class="style28" style="background-color: #C0C0C0; width: 228px;"> 
       <asp:FileUpload ID="exhibitImageFileUpload" runat="server" /> 
      </td> 
      <td class="style20" style="background-color: #C0C0C0; width: 111px;"> 
       <asp:DropDownList ID="storedLocationDropDownList" runat="server"> 
        <asp:ListItem></asp:ListItem> 
        <asp:ListItem>B-15/4</asp:ListItem> 
        <asp:ListItem>B-10/1</asp:ListItem> 
        <asp:ListItem>B-5/4</asp:ListItem> 
       </asp:DropDownList> 
       <asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" 
        ControlToValidate="storedLocationDropDownList" 
        ErrorMessage="Please enter a valid stored location" ForeColor="Red" 
        ondisposed="addExhibitButton_Click">*</asp:RequiredFieldValidator> 
      </td> 
      <td class="style30" style="background-color: #C0C0C0"> 
       <asp:DropDownList ID="DropDownList1" runat="server" 
        DataSourceID="officersSqlDataSource" DataTextField="PoliceID" 
        DataValueField="PoliceID" Width="79px" Height="26px"> 
       </asp:DropDownList> 
       <asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server" 
        ControlToValidate="DropDownList1" 
        ErrorMessage="Please select a valid Officer id from the dropdown list" 
        ForeColor="Red" ondisposed="addExhibitButton_Click">*</asp:RequiredFieldValidator> 
      </td> 
     </tr> 
    </table> 

</div> 
<div style="width: 609px; height: 23px;"> 
       </div> 
<div style="margin-top:12px; width: 232px; text-align:left; font-size:1.3em;"> 

    <asp:SqlDataSource ID="officersSqlDataSource" 
     runat="server" 
     ConnectionString="<%$ ConnectionStrings:CMSSQL3ConnectionString1 %>" 
     SelectCommand="SELECT PoliceID FROM PoliceOfficers"></asp:SqlDataSource> 
    <table align="left"> 
     <tr> 
      <td align="center"> 
       <asp:ValidationSummary ID="ValidationSummary1" runat="server" ForeColor="Red" 
        HeaderText="The following errors occured." /> 
      </td> 
     </tr> 
    </table> 

    </div> 
    <div style="margin-top:12px; width: 456px;"> 

     <table style="width: 450px" align="left"> 
      <tr> 
       <td align="center" colspan="3"> 
        <asp:Label ID="messageLabel" runat="server" BackColor="White" ForeColor="Red" 
         Visible="False"></asp:Label> 
       </td> 
      </tr> 
      <tr> 
       <td align="center" style="width: 96px"> 
        <asp:Button ID="cancelButton" runat="server" Text="Cancel" 
         onclick="cancelButton_Click" height="26px" width="101px" /> 
       </td> 
       <td style="width: 237px"> 
        &nbsp;</td> 
       <td align="center"> 
        <asp:Button ID="addExhibitButton" runat="server" Text="Add Exhibit" 
         onclick="addExhibitButton_Click" /> 
       </td> 
      </tr> 
     </table> 

    </div> 

次のマークと、次のインターフェイスの外観 alt text

でページを持っていますページ上の "展示ボタンを追加"がcliの場合のみcked。私のコードでは、ボタンをクリックしたときにページの検証をチェックするために "if(page.isvalid)"を使いました。しかし、私がクリックした他のどのボタンもバリデーションを起動します...すべてのボタンのクリックがページをロードしようとし、バリデーターをアクションに呼び出すので、私はそれを推測します。どのようにして、「バリデーションボタンを追加する」だけがページ検証をトリガするような検証を回避することができますか?

答えて

1

ボタンとバリデーターにValidationGroupプロパティを設定する必要があります。そうすれば、検証が行われることを制御できます。

ValidationGroupプロパティは、バリデータとボタンに追加して論理単位にグループ化できる任意のタグです。あなたのケースでは、私はこれを行うでしょう:

あなたのバリデータは、展示会の追加アクションに関連しています。

<asp:RequiredFieldValidator ID="RequiredFieldValidator4" ValidationGroup="AddExhibit" ... 

あなたの追加展示をトリガーするボタンの場合。あなたが指摘し、期待通りに判明didntの検証グループを選択するためのドロップダウンメニューを見つけることを期待していたものを実装するのに行ってきました..私

<asp:Button ID="addExhibitButton" ValidationGroup="AddExhibit" 
+0

@And ...ありがとう。検証グループを指定するにはどうすればよいですか?検証要約の名前を入力するか、検証項目をグループ化するために何らかの制御を追加する必要がありますか? – Selase

+0

私が投稿したリンクを見ると、いくつかの例がありますが、もう少し詳しくお話します。 –

+0

@アンドリュー...あなたはそれをすべて言った。私はそのページに行かなくても、あなたが以前に言ったことを例にして再確認しました。私は他のボタンのプロパティをバリデーションを引き起こさないように設定しなければならなかっただけです。または私の場合は、他のすべてのボタンでバリデーションを行わないように設定し、デフォルトでバリデーションを引き起こす「addexhibitbutton」だけを残すことができます。しかし、私は検証グループについて学んだことをとても嬉しく思っています...検証コントロールを適用するためのより良い方法に私の仕事を開きます;) – Selase

関連する問題