2

In Web Application Solution, I have a master page that is located in the root folder. I also have web forms that use this master page and are located in a folder in the root folder.

master page ----located----> root folder

web forms--------located----> root folder/forms

I have JavaScript that cannot run in the web form because this code can't access the source file in the scripts folder. I used the following:

<script type="text/javascript" src="<%= Page.ResolveClientUrl("~/Scripts/stmenu.js") %>"></script>

However, it results in this error:

The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>).

How can I insert the JavaScript, that is located in a separate folder, into the master page?

2 Answers 2

1

Please add runat="server" to the head tag like this

<head runat="server">

Also please use Page.ResolveUrl like this

<script type="text/javascript" src="<%= Page.ResolveUrl("~/Scripts/stmenu.js") %>">
</script>
Sign up to request clarification or add additional context in comments.

Comments

0

Add another asp:contentplaceholder in the <head> section of the Master Page where the Webforms can place their Javascript references and code.

Comments

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.