Click here to Skip to main content
15,885,985 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I've been at this for a day now, and I can't get it to work.

How would you validate the controls on the page with the jquery.validate plugin (its firing but nothing is happening), and at the same time, how would I block the server side method from firing if the form is not valid?

my validation.js:
JavaScript
$(document).ready(function() {
    $("#Form1").validate();
    $('#nationalSociety').rules('add', {
        required: true,
        messages: {
            required: 'National Society cannot be empty'
        }
    });
    $('#participantName').rules('add', {
        required: true,
        messages: {
            required: 'Participant Name cannot be empty'
        }
    });
});
Posted
Updated 25-Jul-10 5:31am
v2

add css class for Required fields as "required" . then it will work fine.

<asp:TextBox ID="nationalSociety" runat="server" CssClass="required"></asp:TextBox>




<pre lang="xml"><head runat="server">
    <title></title>
    <script src="jquery-latest.js"></script>
     <script type="text/javascript" src="jquery.validate.js"></script>
    <script>
        $(document).ready(function() {
        $("#form1").validate();
            $('#nationalSociety').rules('add', {
                required: true,
                messages: {
                    required: 'National Society cannot be empty'
                }
            });
            $('#participantName').rules('add', {
                required: true,
                messages: {
                    required: 'Participant Name cannot be empty'
                }
            });
        });
  </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:TextBox ID="nationalSociety" runat="server" CssClass="required"></asp:TextBox>
        <asp:TextBox ID="participantName" runat="server" CssClass="required"></asp:TextBox>
        <asp:Button ID="Button1" runat="server" Text="Button" />
    </div>
    </form>
</body>


 
Share this answer
 
v2
Comments
Mustafa Ismail Mustafa 25-Jul-10 11:17am    
Ah, sorry, I should have explained that the bulk of the controls I'm trying to validate are normal HTML controls, with the exception being the FileUpload control. Thanks though.

Would you know how I can change the look of the validation messages?
Mustafa Ismail Mustafa 25-Jul-10 13:21pm    
OK, now I have another question.

I know how wrong it is to marry stateful and stateless code, but I need to this time due to an insane number of constraints, primarily related to file uploading.

I need to postback through jQuery, so that the fileUpload can start, but now after validation, the page will simply not postback. I've been at it for sometime now, but nothing.

Ideas? Please?
raju melveetilpurayil 25-Jul-10 13:30pm    
did you mean somthing like this? http://www.phpletter.com/Demo/AjaxFileUpload-Demo/
add a css class .error
XML
<style >
.error
{
    font-size:large;
    color:Red;
    }
</style>
 
Share this answer
 
v2
Comments
Mustafa Ismail Mustafa 25-Jul-10 11:31am    
Reason for my vote of 5
Solved
Mustafa Ismail Mustafa 25-Jul-10 11:31am    
Thanks
raju melveetilpurayil 25-Jul-10 11:35am    
welcome

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