Fileupload上的ValidationGroup

时间:2014-09-23 09:41:38

标签: c# asp.net file-upload

我有一个FormView,其中有FileUpload RequiredFieldValidator,我需要在validationGroupFileUploadButton 1}}不会是PostBackUrl

我的代码:

<asp:FormView ID="fwResultsInsert" runat="server" DataKeyNames="ResultsID" 
            DataSourceID="ObjResults" DefaultMode="Insert">
    <InsertItemTemplate>
        <asp:Label ID="lblImagess" runat="server" Text="Resultat Billede:"></asp:Label>

        <asp:FileUpload ID="fuResultsImages" runat="server" />
        <asp:RequiredFieldValidator ID="rfvImage" runat="server" ErrorMessage="*Her mangler noget!!" ControlToValidate="fuResultsImages"></asp:RequiredFieldValidator>

        <asp:Label ID="lblOutput" runat="server" Text="" Visible="True"></asp:Label>
        <asp:Label ID="Error" runat="server" Text="" Visible="True"></asp:Label>
        <asp:ImageButton ID="imgPicture" runat="server" Visible="True" />
        <br />
        <asp:LinkButton ID="btnInsert" runat="server" CausesValidation="True" 
                    CommandName="Insert" Text="Insæt" onclick="btnInsert_Click" ForeColor="#000000" Font-Underline="True" />
                &nbsp; <asp:LinkButton ID="btnCancel" runat="server" 
                    CausesValidation="False" CommandName="Cancel" Text="Fortryd" ForeColor="#000000" Font-Underline="True" />
    </InsertItemTemplate>
</asp:FormView>

<asp:Button ID="btnHome" runat="server" Text="Forsiden" PostBackUrl="~/BackEnd/Default.aspx" />

我需要在我的FileUpload上进行某种验证,所以当我克隆插入时,fileupload-box中必须有一些东西,atm我有RequiredFieldValidator,但是存在冲突使用另一个Button我在FormView之外,atm当我点击按钮时没有任何事情发生,除非FileUpload中有某些内容,而这不是重点。

1 个答案:

答案 0 :(得分:0)

CausesValidation="false"添加到Button之外的FormView

例如:

<asp:Button ID="btnHome" runat="server" Text="Forsiden" PostBackUrl="~/BackEnd/Default.aspx" CausesValidation="false" OnClick="btnHome_Click" />