How to find application URL while using separate script file in asp.net ?
-
I am trying to find the url of webservice from a page inside a subdirectory in my website. I am using a separate script file referenced in my page. This does not work in the script file
var pgUrl='<%= ResolveUrl("~/assets/WebServices/Admin/UsrRoleService.asmx") %>';
How do I find the application url in the script file ?
-
I am trying to find the url of webservice from a page inside a subdirectory in my website. I am using a separate script file referenced in my page. This does not work in the script file
var pgUrl='<%= ResolveUrl("~/assets/WebServices/Admin/UsrRoleService.asmx") %>';
How do I find the application url in the script file ?
How about having script file in a .ASHX (Generic handler) so that ASP.NET can pre-process and send it...
Vasudevan Deepak Kumar Personal Homepage
Tech Gossips
The woods are lovely, dark and deep, But I have promises to keep, And miles to go before I sleep, And miles to go before I sleep! -
I am trying to find the url of webservice from a page inside a subdirectory in my website. I am using a separate script file referenced in my page. This does not work in the script file
var pgUrl='<%= ResolveUrl("~/assets/WebServices/Admin/UsrRoleService.asmx") %>';
How do I find the application url in the script file ?
Try this code below
var pgUrl='<%= this.Page.ResolveUrl("~/assets/WebServices/Admin/UsrRoleService.asmx") %>';
-
I am trying to find the url of webservice from a page inside a subdirectory in my website. I am using a separate script file referenced in my page. This does not work in the script file
var pgUrl='<%= ResolveUrl("~/assets/WebServices/Admin/UsrRoleService.asmx") %>';
How do I find the application url in the script file ?
By "script file", I assume you mean JavaScript file. You can't call server-side functions from a JavaScript file. You will have to find a way to pass the URL to the JavaScript. One way would be to pass the URL in via the constructor (you would presumably call the JavaScript constructor from an ASPX page in a script block). Though, I have found that I don't typically need to pass the URL of web services to the JavaScript if I am calling one of the methods using AJAX. Instead, I can add a service reference to the page's script manager (or in the case of a user control, the script manager proxy), then I can call the web service by name (e.g.,
ProjectName.UsrRoleService.SomeMethod(someParameter, function (resultData) { alert(resultData); });
).Help a brotha out and vote Managing Your JavaScript Library in ASP.NET as the best ASP.NET article of May 2011.
-
Try this code below
var pgUrl='<%= this.Page.ResolveUrl("~/assets/WebServices/Admin/UsrRoleService.asmx") %>';
This will not work. The OP is trying to call ASP.NET code from an actual .JS file... that's not going to work.
Help a brotha out and vote Managing Your JavaScript Library in ASP.NET as the best ASP.NET article of May 2011.