Click here to Skip to main content
15,915,508 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have this script on .aspx file
JavaScript
$(document).ready(function() {
    $('#<%=txtdateofjoin.ClientID %>').datepicker(
          {

              dateFormat: 'dd/mm/yy'
          }

         );

    Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler);
    function EndRequestHandler(sender, args) {
        $('#<%=txtdateofjoin.ClientID %>').datepicker(
          {

              dateFormat: 'dd/mm/yy'
          }

         );

    }
});



Its working and i tried to make this script as .js file

1) i have Created .js file
2) I dropped a Jquery plugins
3)
JavaScript
/// <reference path="jquery-1.8.3.min.js" />


$(document).ready(function() {
    $('#<%=txtdateofjoin.ClientID %>').datepicker(
          {

              dateFormat: 'dd/mm/yy'
          }

         );

    Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler);
    function EndRequestHandler(sender, args) {
        $('#<%=txtdateofjoin.ClientID %>').datepicker(
          {

              dateFormat: 'dd/mm/yy'
          }

         );

    }
});


named as CustomCalender.js

and I dropped CustomClender.js file to my .aspx but this script not Working.

Why it doen't work? how to rectify it ?
Posted
Updated 11-Dec-14 20:05pm
v2
Comments
Have you checked the Developer Tool Console window?
King Fisher 12-Dec-14 1:24am    
how to check that? Am i doing Right?
Do you have FireBug installed on FireFox? Else just press F12 in any browser and load the page again, left that F12 Window open. And see that there is one Console Tab on that window. Click and see what errors are listed there.
King Fisher 12-Dec-14 1:51am    
i have that but the Console Tab is Empty
After opening that window, did you reload the page again?

1 solution

Hey King,

I got the problem. Actually, you are trying to ClientID, which is unknown to JavaScript. When you place the same code in the Page, it is actually converted to the appropriate ID of the Control, because .NET Engine converts that while rendering. You can check how it converts the code to render the actual ID in Developer Tool's Script Tab. Click on that Tab, see the inline script file.

But if you write the same code in External js file, it cannot convert that code. You can check following the same procedure. See that the code is as it is. So, the Error.

So, I suggest you to keep the code inside the Page itself. Else, you have to either replace the <%=txtdateofjoin.ClientID %> with the actual ID of control after rendering (you can check that in the rendered HTML, by inspecting the element). You can also make ClientIDMode to static, so that the ID will not change and you can only use $('#txtdateofjoin') anywhere.
 
Share this answer
 
v2
Comments
King Fisher 12-Dec-14 4:12am    
Thanks .But I have Controls in ContentPlaceHolder ,so can't i make this as Externel File?
Do i have to keep the Script in .aspx page itself?
As I said, if you want to have them in external file, you have to set ClientIDMode = static. Try with that.
King Fisher 12-Dec-14 5:47am    
Not Woring :(

I referred this
http://www.mindfiresolutions.com/ClientIDMode-on-AspNet-40-1151.php

it says ClientIDMode property on DotNet Framework 4.0 but I have 3.5 :(
Okay, then just go to the rendered html and check what is the ID of that TextBox. Just copy that and replace in the external js file.
King Fisher 12-Dec-14 6:08am    
external file is working when its an normal .aspx page (means without Master Form)

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