0

I am doing something like the following in my master page:

                <asp:Image data-toggle="popover" data-placement="bottom"
                    onmouseover="this.src='../Content/Images/icon-hover.png'"
                    onmousedown="this.src='../Content/Images/icon-hover.png'"
                    onmouseout="this.src='../Content/Images/icon.png'"
                    runat="server"
                    ImageUrl="../Content/Images/icon.png"></asp:Image>

However, I started noticing a problem when I put aspx pages that use this master page 2 levels down from the root directory:

For example:

Customers > Maintenance > Customers.aspx

..Content/ only handles pages in paths that are one level such as:
Customers > Customers.aspx

Any suggestions to make this programmatic so I can do something similar to the ~ in JavaScript like I can in asp.net server-side?

1 Answer 1

1

You can try something like this:

onmouseover="this.src = getResolvedUrl('Content/Images/icon-hover.png')"

with the Javascript utility function:

<script type="text/javascript">
    function getResolvedUrl(url) {
        return '<%= ResolveUrl("~/") %>' + url;
    }
</script>
Sign up to request clarification or add additional context in comments.

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.