Moons
Moons

Reputation: 3854

ResolveUrl Illegal Characters in Path

I am getting the error by this code

 <script runat="server" type="text/javascript" src='<%# ResolveUrl("js/excanvas.min.js") %>'></script>

Please note i am using runat="server" and it is really required.

Any help is appreicated

Thanks

Upvotes: 1

Views: 635

Answers (2)

Duncan
Duncan

Reputation: 11

For anyone else having this problem, DevExpress controls do not allow Page.Header.Databind as it invalidates the viewstate so you can't use <%# ResolveUrl() %> and runat=server does not work for <script> tags. To get around this problem, use the following:

For <link> tags, simply add runat=server and use the tilde:

<link rel="stylesheet" href="~/css/styles.css" type="text/css" runat="server" />

For <script> tags, ensure your <head> tag includes runat=server then do the following:

<head runat="server">
    <asp:Literal ID="jsJquery" runat="server" />
</head>

In code behind:

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    Me.jsJquery.Text = "<script type=""text/javascript"" src=""" & Page.ResolveUrl("~/jscript/jquery.js") & """></script>"
End Sub

Upvotes: 0

Claudio Redi
Claudio Redi

Reputation: 68420

I don't see any illegal character but If you're not in data binding context you should use <%= isntead of <%#

src='<%= ResolveUrl("js/excanvas.min.js") %>'

As a side note, runat="server" is not required for this case

Upvotes: 1

Related Questions