All ASP.NET controls have a ClientID, which matches the ID generated
in the HTML, so you should be able to replace:

"<% = namePostcode %>"
with
"<%= namePostcode.Replace(":","\:") %>"

and

$("[EMAIL PROTECTED]" + <%=chkLinkAccount.ClientID %> + "]")
with
$("#<%=chkLinkAccount.ClientID %>")



--Sam

On Jul 17, 7:46 am, Gregoriusness <[EMAIL PROTECTED]> wrote:
> Hey all,
>
> I'm trying to implement validation using the Validation plugin on an
> ASP.Net (1.1 :(  ) form.  I'm having trouble with setting up the
> rules, because they require the form element's "name" tag to assign
> the rule to, and ASP.Net does some funky stuff with the names (changes
> a name="myname" to "myUserControl:myname").
>
> I can get that client side name by calling the name the same as the
> ID, and on server side getting the fomrelement.ClientID, then doing a
> String.Replace("_", ":").
>
> But now it seems JQuery doesnt like that name because it has a colon
> (:) in it.  Putting "quotation marks" around it in the rules
> declaration doesn't seem to help.
>
> Any ideas how i can get my rules working successfully?  My best
> solution would be fore the rules to accept a javascript variable
> (which contains the actual element name) which i can declare at the
> top of my page, and get the ClientID > Client Name values for use
> later on.  Or alternatively telling Validation plugin to use ID
> instaed of Name attribute.
>
> Here's my code:
>
>         $().ready(function()
>         {
>             $("#Short").validate({
>                 rules: {
>                     "<% = namePostcode %>": {
>                         required: function() {
>                             return $("[EMAIL PROTECTED]" + <%
> =chkLinkAccount.ClientID %> + "]").is(":checked");
>                                                 }
>                     }
>                         },
>                         messages: {
>                                 "<% = namePostcode %>": {
>                                                 required: "Please enter your 
> postcode"
>                                 }
>                         },
>                         errorPlacement: function(error, element) {
>                     if ( element.is(":checkbox") )
>                         error.appendTo( element.parent());
>                     else
>                         error.appendTo( element.parent() );
>                 }
>                     });
>
> Whic Generates the following:
>
>  $().ready(function()
>         {
>             $("#Short").validate({
>                 rules: {
>                     "ucFoxtelAccount:txtPostcode": {
>                         required: function() {
>                             return $("[EMAIL PROTECTED]" +
> ucFoxtelAccount_chkLinkAccount + "]").is(":checked");
>                                                 }
>                     }
>                         },
>                         messages: {
>                                 "ucFoxtelAccount:txtPostcode": {
>                                                 required: "Please enter your 
> postcode"
>                                 }
>                         },
>                         errorPlacement: function(error, element) {
>                     if ( element.is(":checkbox") )
>                         error.appendTo( element.parent());
>                     else
>                         error.appendTo( element.parent() );
>                 }
>                     });
>
> And is trying to validate the following form element:
>
>         <div class="fieldcontainer">
>
>          <div class="fieldlabel"> Accountholder Postcode: </div>
>          <div class="fieldmandatory">*</div>
>          <div class="fieldinput postcode">
>                         <input name="ucFoxtelAccount:txtPostcode" type="text" 
> maxlength="4"
> id="ucFoxtelAccount_txtPostcode" class="required numeric textbox
> postcode" MinLength="4" />
>          </div>
>         </div>
>
> Thanks in advance
> Greg

Reply via email to