JQuery unable to find controls on a page [modified]
-
Hi I have a JQuery date mask, but when I run the page it throws an error "Microsoft JScript runtime error: Object doesn't support this property or method". Now, the control that this particular JQuery is meant to be working is added dynamically to a repeater control. Through this, I have looked at the ids of the control, where it was breaking and stopping in Visual Studio and what is being shown on the aspx page. The ids are identical except of the "#" that JQuery has at the start, which is not on the page. In my JQuery code I have: JQuery(function ($) { $('#<%=date.ClientID %>').mask("99/99/9999"); }); Is there away to tell JQuery not to include the "#" when finding the control? I have used UniqueID but this changes any underscore into "$", which is not the same as what is on the page. My only problem is with "#" sign at the start of the ID. I have even added an alert box to check that textbox was there and it came back as null. I have tried even adding a CssClass attribute to the textbox, but this through the same error, too. Please note that the custom user control that has the textbox is added programatically to the repeater. Can anyone help? Thanks
modified on Saturday, December 4, 2010 4:21 AM
-
Hi I have a JQuery date mask, but when I run the page it throws an error "Microsoft JScript runtime error: Object doesn't support this property or method". Now, the control that this particular JQuery is meant to be working is added dynamically to a repeater control. Through this, I have looked at the ids of the control, where it was breaking and stopping in Visual Studio and what is being shown on the aspx page. The ids are identical except of the "#" that JQuery has at the start, which is not on the page. In my JQuery code I have: JQuery(function ($) { $('#<%=date.ClientID %>').mask("99/99/9999"); }); Is there away to tell JQuery not to include the "#" when finding the control? I have used UniqueID but this changes any underscore into "$", which is not the same as what is on the page. My only problem is with "#" sign at the start of the ID. I have even added an alert box to check that textbox was there and it came back as null. I have tried even adding a CssClass attribute to the textbox, but this through the same error, too. Please note that the custom user control that has the textbox is added programatically to the repeater. Can anyone help? Thanks
modified on Saturday, December 4, 2010 4:21 AM
No you can't eliminate the #, its how JQuery identifies element IDs. It sounds as though the getting the element isn't the problem, its the mask function. Are you sure you have included the proper javascript links on your page?
I know the language. I've read a book. - _Madmatt
-
No you can't eliminate the #, its how JQuery identifies element IDs. It sounds as though the getting the element isn't the problem, its the mask function. Are you sure you have included the proper javascript links on your page?
I know the language. I've read a book. - _Madmatt
This is how I have the code set up on the control, as you can see I have the JQuery function commented until I can understand and solve what is going wrong! <%@ Control Language="C#" AutoEventWireup="true" CodeBehind="MaskControl.ascx.cs" Inherits="Prototype.CommonControls.MaskControl" > </x-turndown>
-
This is how I have the code set up on the control, as you can see I have the JQuery function commented until I can understand and solve what is going wrong! <%@ Control Language="C#" AutoEventWireup="true" CodeBehind="MaskControl.ascx.cs" Inherits="Prototype.CommonControls.MaskControl" > </x-turndown>
And
$('.dateMask')
is a valid element? Have you tried$(document).ready()
{
$('.dateMask').mask("99/99/9999");
});It doesn't have anything to do with the problem but you should place the javascript in a seperate file rather than in the control. It will improve the maintainability of your code.
I know the language. I've read a book. - _Madmatt
-
And
$('.dateMask')
is a valid element? Have you tried$(document).ready()
{
$('.dateMask').mask("99/99/9999");
});It doesn't have anything to do with the problem but you should place the javascript in a seperate file rather than in the control. It will improve the maintainability of your code.
I know the language. I've read a book. - _Madmatt
The code I am using is from a website called "http://digitalbush.com/projects/masked-input-plugin" and I followed was given on the site. As shown below: JQuery(function ($) { $('#<%=date.ClientID %>;').mask("99/99/9999"); }); When I followed the example given on the website, all I was getting is the Microsoft JScript error message. Then I have tried all various ways with CssClass. I will try the example you have given, but I can't try it until Monday. Should it not work, what other advice can you give for me to try?
-
The code I am using is from a website called "http://digitalbush.com/projects/masked-input-plugin" and I followed was given on the site. As shown below: JQuery(function ($) { $('#<%=date.ClientID %>;').mask("99/99/9999"); }); When I followed the example given on the website, all I was getting is the Microsoft JScript error message. Then I have tried all various ways with CssClass. I will try the example you have given, but I can't try it until Monday. Should it not work, what other advice can you give for me to try?
That is the problem with just copying code without understanding it.
I know the language. I've read a book. - _Madmatt
-
That is the problem with just copying code without understanding it.
I know the language. I've read a book. - _Madmatt
Hi Well, I applied the following code, and added some more: $(document).ready() { $('.dateMask').mask("99/99/9999"); }); To check that JQuery was picking up the ids of the control, I added $('input[class$=dateMask]') and sent the output to an alert box. Thankfully JQuery found the control by class, but fell over when applying the mask. So, the problem lies with the plugin!
-
Hi Well, I applied the following code, and added some more: $(document).ready() { $('.dateMask').mask("99/99/9999"); }); To check that JQuery was picking up the ids of the control, I added $('input[class$=dateMask]') and sent the output to an alert box. Thankfully JQuery found the control by class, but fell over when applying the mask. So, the problem lies with the plugin!
Alert boxes are not debugging tools. You have the source, set a break point and debug.
I know the language. I've read a book. - _Madmatt