0

I Have usercontrol and i registered the following javascript method in code behind :

changeSelectedMenu(controlID);

the previous method is declared in JScript.js file so i registered it also .

but the following exception has been thrown :

 Microsoft JScript runtime error: Object expected

The result page is :

<script src="~/Scripts/JQuery.js" type="text/javascript"></script>
<script src="~/Scripts/JScript.js" type="text/javascript"></script>
<script type="text/javascript">
//<![CDATA[
changeSelectedMenu('ctl00_ctl00_cntMain_procedureContentHolder_procedureMenu_appointmentsLink');//]]>
</script>

Is There anyone can help me to workaround this issue???

1 Answer 1

1

These aren't valid paths to your JavaScript:

<script src="~/Scripts/JQuery.js" type="text/javascript"></script>
<script src="~/Scripts/JScript.js" type="text/javascript"></script>

They need to be relative to the page or to the site root, for example:

<script src="/Scripts/JQuery.js" type="text/javascript"></script>
<script src="/Scripts/JScript.js" type="text/javascript"></script>

While ~/ works for resolving a path on the server-side, the browser doesn't know how to handle this. There are some other work-arounds in this question for making it work and still being app-relative.

Sign up to request clarification or add additional context in comments.

2 Comments

I already include javascript files : <asp:ScriptReference Path="Scripts/JScript.js" />
@DEVMBM - According to your question, they're rendering as ~/ in the page, is that not the case?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.