boraer
boraer

Reputation: 419

jquery master page problem

i am developing an asp.net project and i use jquery with it but when I use masterpage with content page. My jquery code does not working but if ı use in a normal page without master jquery work efficiently.

<script type="text/javascript" language="javascript" src='<%= Page.ResolveClientUrl("~/js/Default.js") %>' ></ script>

I use this in the master page for resolation.

In my code when click a button. a timer starts and button disabled until timer finishes Thats all but not working with master page

Upvotes: 0

Views: 826

Answers (2)

Michael
Michael

Reputation: 406

I believe you should try using ResolveUrl instead of ResolveClientUrl.

When using ResolveClientUrl the path is resolved relative to the location of the master page instead of the current page. ResolveUrl will resolve relative to the application root.

Upvotes: 1

Peter
Peter

Reputation: 9712

My solution is below. I ran into this issue a while ago. To fix it I changed the src tag so that it uses databinding ("#") instead of resposne write ("="). So in your code behind you have to call Page.Header.DataBind to resolve it.

<head runat="server">
    <title></title>
    <script type="text/javascript" language="javascript" src='<%# ResolveClientUrl("~/JScript.js") %>' ></script>

    <asp:ContentPlaceHolder id="head" runat="server">
    </asp:ContentPlaceHolder>
</head>

Code Behind:

Partial Class MasterPage
    Inherits System.Web.UI.MasterPage

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Page.Header.DataBind()
    End Sub
End Class

Upvotes: 0

Related Questions