lapucca
asked on
Got jScript error after I added a regular expression validator to a textbox in gridview's edit template
Hi, I'm using vs2012
I have a gridview where the last column is a datetime column and I also have changed this column from boundfield to a Templatefield. I used the script from here http://forums.asp.net/t/1668230.aspx?JQuery+Datepicker+for+edit+item+template+textbox+in+gridview
and the calendar pops up nicely until I added a regular expression validator to the edit template. I got the following error when I click the Edit button on the grid. The code highlited is " $("input[type=text][id*=tx tExpDate]" ).datepick er();" and the error is:
0x800a01b6 - Microsoft JScript runtime error: Object doesn't support property or method 'datepicker'
Attached is my gridview controls code, including the validator setting. If I remove the validator then it works fine again with the popup calendar.
Thank you.
grid.html
I have a gridview where the last column is a datetime column and I also have changed this column from boundfield to a Templatefield. I used the script from here http://forums.asp.net/t/1668230.aspx?JQuery+Datepicker+for+edit+item+template+textbox+in+gridview
and the calendar pops up nicely until I added a regular expression validator to the edit template. I got the following error when I click the Edit button on the grid. The code highlited is " $("input[type=text][id*=tx
0x800a01b6 - Microsoft JScript runtime error: Object doesn't support property or method 'datepicker'
Attached is my gridview controls code, including the validator setting. If I remove the validator then it works fine again with the popup calendar.
Thank you.
grid.html
ASKER
Hi,
No, there is no duplicate name of txtExpDate. I'm attaching the site.master file. Thank you for your help.
Site.txt
No, there is no duplicate name of txtExpDate. I'm attaching the site.master file. Thank you for your help.
Site.txt
I would add a check on length before assigning the datepicker like:
if($("input[type=text][id* =txtExpDat e]").lengt h>0)
$("input[type=text][id*=tx tExpDate]" ).datepick er();
if($("input[type=text][id*
$("input[type=text][id*=tx
ASKER
Hi, I did as you suggested but at run time when I click on that date column in Edit mode, I get the same error and VS highlite the same loc. There is date in that column no doubt. But somehow there is a conflict between the validator control and the jQuery datepicker.
<script>
$(document).ready(function () {
Sys.WebForms.PageRequestMa nager.getI nstance(). add_endReq uest(bindP icker);
bindPicker();
});
function bindPicker() {
if ($("input[type=text][id*=t xtExpDate] ").length > 0)
$("input[type=text][id*=tx tExpDate]" ).datepick er();
}
</script>
<script>
$(document).ready(function
Sys.WebForms.PageRequestMa
bindPicker();
});
function bindPicker() {
if ($("input[type=text][id*=t
$("input[type=text][id*=tx
}
</script>
When you are in the edit mode, can you view source and share the html from the browser.
ASKER
Hi, Sorry it took a while but I was called to work on something else.
Attached is the Source code from Browser. The code works fine until I added the Regular expression validator control. You can see the first row of the grid (table) int he source, there is the validator. This source is taken when I was in Grid's Edit mode, after the pop up jScript error. appreciate your help, thank you.
ValidatorJscriptError.html
Attached is the Source code from Browser. The code works fine until I added the Regular expression validator control. You can see the first row of the grid (table) int he source, there is the validator. This source is taken when I was in Grid's Edit mode, after the pop up jScript error. appreciate your help, thank you.
ValidatorJscriptError.html
replace :
<script>
$(document).ready(function () {
Sys.WebForms.PageRequestManager.getInstance().add_endRequest(bindPicker);
bindPicker();
});
function bindPicker() {
if ($("input[type=text][id*=txtExpDate]").length > 0)
$("input[type=text][id*=txtExpDate]").datepicker();
}
</script>
by : <script>
jQuery(document).ready(function ($) {
Sys.WebForms.PageRequestManager.getInstance().add_endRequest(bindPicker);
bindPicker();
});
function bindPicker() {
if (jQuery("input[type=text][id*=txtExpDate]").length > 0)
jQuery("input[type=text][id*=txtExpDate]").datepicker();
}
</script>
ASKER
Hi Lea,
I replace with your code and gets the same jscript error at the same LOC,
jQuery("input[type=text][i d*=txtExpD ate]").dat epicker();
Also, I want to bind to datepicker even if it's a blank field. I guess I would remove the if lenght> 0 LOC. Thank you.
I replace with your code and gets the same jscript error at the same LOC,
jQuery("input[type=text][i
Also, I want to bind to datepicker even if it's a blank field. I guess I would remove the if lenght> 0 LOC. Thank you.
we can't help you without having a link to your page
ASKER
This is an Intranet site so I can't provide you with access. i did submit the source code from browser, that doesn't work?
I don't see your project attached anywhere, just a page, I don't want to search all the plugins one by one, I would prefer that you to open a port on your router during some minutes :)
ASKER
Lea,
I understand that it will be more clear with the entire project/solution submitted. This is a ldap program that access our AD directory an modifies some accounts. I don't think it's a good idea to either give you access or upload the project. Even if I remove some sensitive code/information, I'm afraid if I left out something sensitive than that would be a problem. Okay, please close ticket.
I understand that it will be more clear with the entire project/solution submitted. This is a ldap program that access our AD directory an modifies some accounts. I don't think it's a good idea to either give you access or upload the project. Even if I remove some sensitive code/information, I'm afraid if I left out something sensitive than that would be a problem. Okay, please close ticket.
you can just create a separate site, test site... I was assuming you already have one, you should.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I look at txtedit property but it just lists a lot of functions.
txtEdit.png
txtEdit.png
ASKER
Attached is the screen shot of the context field of txtedit. Please let me know if there is other field that you would like me to expand and take screen shot. I'm not sure what I'm looking for. Thank you.
txtedit2.png
txtedit2.png
ASKER
I suspect the previous state wasn't selecting the txtbox becuase it can't just use asp.net id. I believe it needs to use the client id. How to change this select statement to incorporate the clientId of txtExpDate? Something like txtExpDate.ClientID
function bindPicker() {
$("input[type=text][id*=tx tExpDate]" ).datepick er();
}
Thank you.
function bindPicker() {
$("input[type=text][id*=tx
}
Thank you.
Usually you do like
But I don't think you will be able to use ClientID because the input is inside of a GridView.
: <%=txtExpDate.ClientID%>
But I don't think you will be able to use ClientID because the input is inside of a GridView.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Lea,
In Debug mode, it shows that the correct textbox in Gridview Edit mode is selected. Please see the 2 attached screen shot. In the VS Intellisense also shows up datepicker when I type the :.: after the select statement, $("input[type=text][id*=tx tExpDate]" )
Because of the Validator control, this creates the MS jScript error. Thank you.
txtedit3.png
txtedit4.png
In Debug mode, it shows that the correct textbox in Gridview Edit mode is selected. Please see the 2 attached screen shot. In the VS Intellisense also shows up datepicker when I type the :.: after the select statement, $("input[type=text][id*=tx
Because of the Validator control, this creates the MS jScript error. Thank you.
txtedit3.png
txtedit4.png
doesn't look like a jQuery object...
could you do the same screen copy with code in place from my comment ID: 40568338 ?
could you do the same screen copy with code in place from my comment ID: 40568338 ?
ASKER
Lea, I searched for 40568338 here and it brings me right back to this question. How do I get there?
I'm not sure what do you mean about it doesn't look like a jQuery object. It seems t me it got passed the "if" select statement. The screen shots I submitted is for the object selected using "($("input[type=text][id*= txtExpDate ]")"
the object selected array, [0], when expanded seems to return the correct textbox object selected, the default value of "1/29/2014", is the correct date and the name, "+ name "ctl00$MainContent$gridAcc ounts$ctl1 1$txtExpDa te" String
seems right to me too.
Thank you.
I'm not sure what do you mean about it doesn't look like a jQuery object. It seems t me it got passed the "if" select statement. The screen shots I submitted is for the object selected using "($("input[type=text][id*=
the object selected array, [0], when expanded seems to return the correct textbox object selected, the default value of "1/29/2014", is the correct date and the name, "+ name "ctl00$MainContent$gridAcc
seems right to me too.
Thank you.
replace :
<script>
$(document).ready(function () {
Sys.WebForms.PageRequestManager.getInstance().add_endRequest(bindPicker);
bindPicker();
});
function bindPicker() {
if ($("input[type=text][id*=txtExpDate]").length > 0)
$("input[type=text][id*=txtExpDate]").datepicker();
}
</script>
by : <script>
jQuery(document).ready(function ($) {
Sys.WebForms.PageRequestManager.getInstance().add_endRequest(bindPicker);
bindPicker();
});
function bindPicker() {
if (jQuery("input[type=text][id*=txtExpDate]").length > 0)
jQuery("input[type=text][id*=txtExpDate]").datepicker();
}
</script>
ASKER
Lea,
Your new code got rid of jScript error, but, it also got rid of the pop up calendar. When I click txtExpDate cell, the calendar no longer pops up.
Thank you.
Your new code got rid of jScript error, but, it also got rid of the pop up calendar. When I click txtExpDate cell, the calendar no longer pops up.
Thank you.
that's a good thing, that just mean, the field is not present in the page when you run the code
<script>
jQuery(document).ready(function ($) {
Sys.WebForms.PageRequestManager.getInstance().add_endRequest(bindPicker);
bindPicker();
});
function bindPicker() {
if (jQuery("input[type=text][id*=txtExpDate]").length > 0)
{
jQuery("input[type=text][id*=txtExpDate]").datepicker();
}
else {
alert("field not found !!");
}
}
</script>
with Chrome browser, do a right click near the field, choose view source and post it here after removing sensitive data if needed
ASKER
Lea,
I tested the new code you provided in both Chrome and IE. It seems that the textbox field is not found when the gridview is not in edit mod, which is correct, because the alert box would pop up. Once I clicked the Edit on the grid then no alert pops up. Also, in Chrome and Firefox no jScript error but in IE it still shows up .
Also in IE I can put break point in the script. It does break at this line, which means it does find the field. But it also gives jscript error when I run this loc.
jQuery("input[type=text][i d*=txtExpD ate]").dat epicker();
Thank you.
I tested the new code you provided in both Chrome and IE. It seems that the textbox field is not found when the gridview is not in edit mod, which is correct, because the alert box would pop up. Once I clicked the Edit on the grid then no alert pops up. Also, in Chrome and Firefox no jScript error but in IE it still shows up .
Also in IE I can put break point in the script. It does break at this line, which means it does find the field. But it also gives jscript error when I run this loc.
jQuery("input[type=text][i
Thank you.
ASKER
Attached is the Firebug console with error when I run the script. It doesn't recognize datepicker()?
firebug-err.png
firebug-err.png
ASKER
Lea,
What about getting rid of the Regular Expression Control form asp.net that's causing the jscript error and instead is it possible to write a jscript to run after user enters a date manually instead of using the date picker?
What about getting rid of the Regular Expression Control form asp.net that's causing the jscript error and instead is it possible to write a jscript to run after user enters a date manually instead of using the date picker?
ASKER
Please close this. I found an alternative solution. I validate in the code behind and display an error message if there is an issue. thank you.
Try adding a CssClass to the textbox and find the control via $('.someclassname ') for troubleshooting purpose.