ASP.Net routing problem
I defined my routed page as following:
routes.MapPageRoute(
"gans",
"MyRoutedPage",
"~/GardenTemplates/template4.aspx");
The web form template4.aspx has an image gallery: when user presses a small image, it is displayed in big image:
//template4.aspx.cs
string imageName = "../Images2/garden/2206/SomePhoto.jpg";
img.At开发者_Go百科tributes["onclick"] = "LoadGallery('" + imageName + "');
//template4.aspx
<script type="text/javascript">
function LoadGallery(imageName) {
var picture = document.getElementById('Gallery');
if (picture != null) {
picture.src = imageFile;
}
}
</script>
This code works fine if I browse to /GardenTemplates/template4.aspx but it showse a directory list of GardenTemplates/ when I press the small image from MyRouted page. My guess is that Routing can not display files in upper directory (as Images2 is located in parent directory regarding the template4.aspx page). How can I solve this problem?
ResolveClientUrl should help. This looks like a client side issue. Try something like -
img.Attributes["onclick"] = "LoadGallery('" + ResolveClientUrl(imageName) + "');
or...
img.Attributes["onclick"] = "LoadGallery('" + ResolveClientUrl("~/Images2/garden/2206/SomePhoto.jpg") + "');
http://msdn.microsoft.com/en-us/library/system.web.ui.control.resolveclienturl%28v=VS.90%29.aspx
精彩评论