This is a migrated thread and some comments may be shown as answers.

Refering .js file from content page

2 Answers 23 Views
UI for ASP.NET AJAX in ASP.NET MVC
This is a migrated thread and some comments may be shown as answers.
Nalini
Top achievements
Rank 1
Nalini asked on 01 Sep 2010, 07:39 PM

I am getting “Micorsoft Jscript runtime error: Object required” error when I try to refer the .js file that refer a Radcontrol. ie.,"document.getElementById('<%=txtTime.ClientID%>')."  Please let me know where i am going wrong.  Any help is appreciated.

I originally have the following JavaScript function in the content page and worked just fine. Now I am trying to move my java script to .js file.

I have the RadScriptManager on the master page. I do not want to load the .js code at the master  page, so I added a ScriptManagerProxy in my content page as below.
   <asp:ScriptManagerProxy ID="ScriptManagerProxy1" runat="server">
       <Scripts>
        <asp:ScriptReference Path="../JavaScript/test.js" />
       </Scripts>
    </asp:ScriptManagerProxy>

Sample Content of my test.js file

function getTime(sender, args){
         var strTime =document.getElementById('<%=txtTime.ClientID%>').value;
                  args.IsValid = true;   
          }

Thanks in advance.

2 Answers, 1 is accepted

Sort by
0
Vinkel
Top achievements
Rank 1
answered on 02 Sep 2010, 11:16 AM
I bet you get the same error when you use server tags and client ids in test.js file for asp Button (for example), dear Nalini, don't you? My way is to define global js variable like so (inside pageLoaded client event of MS Ajax framework):

var txtTimeObj = document.getElementById('<%=txtTime.ClientID%>')

and then use txtTime object directly in test.js file.

function getTime(sender, args)
{
         var strTime =txtTimeObj.value;
         args.IsValid = true;   
}

Good luck!

-J
0
Nalini
Top achievements
Rank 1
answered on 09 Sep 2010, 06:51 PM
Thank you very much for your suggestion.

Tags
UI for ASP.NET AJAX in ASP.NET MVC
Asked by
Nalini
Top achievements
Rank 1
Answers by
Vinkel
Top achievements
Rank 1
Nalini
Top achievements
Rank 1
Share this question
or