Click here to Skip to main content
15,891,529 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
I have a form in which I have two textboxes and one fileupload control, I am using required field validator on one textbox and on Fileupload control, When I am clicking the submit button, its showing the validation message but disabling the fileupload control.

I also have second button for Cancel, clicking on which redirects to previous page, when I am clicking this button its also disabling the fileuploadcontrol and not redirecting. Below is my code


XML
<asp:FileUpload ID="FileUpload1" runat="server" />
 <asp:RequiredFieldValidator ID="rfvFileupload" ValidationGroup="validate" runat="server"
                                                ControlToValidate="FileUpload1"></asp:RequiredFieldValidator>


  <asp:TextBox ID="txtSubj" runat="server" ></asp:TextBox><asp:RequiredFieldValidator
                                ID="rfvSubject" ControlToValidate="txtSubj" runat="server" Display="Dynamic"
                                EnableClientScript="true" ErrorMessage="* required" ValidationGroup="validate" />


<asp:Button ID="btnupload" runat="server" Text="Send" ValidationGroup="validate"
                    OnClick="btnupload_Click">
                <asp:Button ID="btncancel" runat="server" Text="Cancel" OnClick="btncancel_Click"
                    />
Posted
Comments
VICK 20-Aug-13 2:16am    
Validations are being called against the click event of all buttons on the page if not grouped...

So manage your controls in validation groups to avoid the validations being called on each button click....
Syed Salman Raza Zaidi 20-Aug-13 2:50am    
I have validation group set for Send Button you can see in the code

1 solution

Required field validator does not disable any other form controls when it fails the validation. Try this below sample

XML
<asp:FileUpload ID="FileUpload1" runat="server" />
        <asp:RequiredFieldValidator ID="rfvFileupload" ValidationGroup="validate" runat="server" Display="Dynamic"
                                          ErrorMessage="* required" ControlToValidate="FileUpload1"></asp:RequiredFieldValidator>


        <asp:TextBox ID="txtSubj" runat="server" ></asp:TextBox>
        <asp:RequiredFieldValidator ID="rfvSubject" ControlToValidate="txtSubj" runat="server" Display="Dynamic"
                                EnableClientScript="true" ErrorMessage="* required" ValidationGroup="validate" />


        <asp:Button ID="btnupload" runat="server" Text="Send" ValidationGroup="validate" onclick="btnupload_Click" />
        <asp:Button ID="btncancel" runat="server" Text="Cancel" onclick="btncancel_Click" />
 
Share this answer
 
Comments
Syed Salman Raza Zaidi 20-Aug-13 3:14am    
I don't know why its disabling :(

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