How to resolve relative path problems with JS … This is critical with masterpage in

Folks, now suppose you used master pages in ur webapps. Now you have some login and default pages at the solution level along with master page also.

Now rest of all pages/forms (what ever you say) are in separate folder like all administrative work pages are in Admin folder.

Here JS relative path problem occurs most of the time. So use below trick …..

  1. place literal control in <head> section of master page.
  2. in master.cs write below code in page load method…
StringBuilder sb = new StringBuilder();
sb.AppendLine(String.Format(“<script type=\”text/javascript\” src=\”{0}\”></script>”, ResolveClientUrl(“~/js/jquery-1.4.2.min.js”)));
sb.AppendLine(String.Format(“<script type=\”text/javascript\” src=\”{0}\”></script>”, ResolveClientUrl(“~/JS/jquery.ui.core.js”)));
LiteralScriptTags.Text = sb.ToString();
Hope this will help someone…

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s