I have a asp.net web content from that have a asp.net textbox and I want to use Plugin/Validation but it is not working with me here is my code:
<%@ Page Title="" Language="C#" MasterPageFile="~/Master.Master" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="IMAM_APPLICATION.WebForm1" %>
<%@ Register assembly="AjaxControlToolkit" namespace="AjaxControlToolkit" tagprefix="asp" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
<script src="js/jquery-1.4.1.js" type="text/javascript"></script>
<script src="js/jquery.validate.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function() {
$.validator.addMethod("#<%=TextBox1.ClientID %>", function(value, element) {
return this.optional(element) || /^(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{8,16}$/i.test(value);
}, "Passwords are 8-16 characters with uppercase letters, lowercase letters and at least one number.");
});
</script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="ContentPlaceHolder2" runat="server">
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
</asp:Content>
Well I am unsure what the problem is as this does not tell me much “not working”.
Just looking at your code I am trying to see might cause it not to work.
First you don’t have the validate method hooked up to any form. I don’t think you can run it without hooking it up to a form tag.
Notice how they tie the validate field.
Next
I think your doing your .addMethod wrong
You have what is above but if you look at the documentation.
see how the first paramter is “name” not “id”. Name is like the name of this new method.
So this addMethod could be called “Test101” that would be the name. Or like in the examle you see they named it “math”
next you would do something like this
So it would me something like this. You would put the textboxId in the validate method of the form and then you call your .addMethod inside that id. In my case I used the .addMethod called “math” and I believe you just set it to “true” to make it required and to run.
I have not tested this so I will try to find some examples that actually run.
Edit
Here is what the master page.
see it does have a form id and when you hook this master page with an aspx page you should have this.
So try that if that will be good enough for hooking it up.