What you want to see on DotNetFunda.com ?
DotNetFunda.Com Logo
Twitter TwitterLinkedIn
YouTubeGoogle
 Online : 30099 |  Welcome, Guest!   Register  Login
 Home > Forums > C# > Link build through a class and get that in online code ...
Nerdanalysis

Link build through a class and get that in online code

Replies: 0 | Posted by: Nerdanalysis on 5/9/2012 | Category: C# Forums | Views: 289 | Status: [Member] | Points: 10  


Hi All,

I have following method in business logic layer class to generate the links for the pages.

private static string BuildAbsolute(string relativeUri)
{
// get current uri
Uri uri = HttpContext.Current.Request.Url;
// build absolute path
string app = HttpContext.Current.Request.ApplicationPath;
if (!app.EndsWith("/")) app += "/";
relativeUri = relativeUri.TrimStart('/');
// return the absolute path
return HttpUtility.UrlPathEncode(String.Format("http://{0}:{1}{2}{3}", uri.Host, uri.Port, app, relativeUri));
}

public static string ToSubCategory(string categoryId, string subCategoryId, string page)
{
if (page == "1")
return BuildAbsolute(String.Format("CommonPages/WeddingPlanning.aspx?categoryId={0}&subCategoryId={1}", categoryId, subCategoryId));
else
return BuildAbsolute(String.Format("CommonPages/WeddingPlanning.aspx?categoryId={0}&subCategoryId={1}&Page={2}", categoryId, subCategoryId, page));
}
public static string ToSubCategory(string categoryId, string subCategoryId)
{
return ToSubCategory(categoryId, subCategoryId, "1");
}

I want to call this function in html inline code in following javascript code....but nothing is coming up....

<script language="javascript" type="text/javascript">
function sendtopage(categoryId, subCategoryId) {
try {
location.href = Link.ToSubCategory(categoryId, subCategoryId);
}
catch (ex) {
alert(ex);
}
}
</script>

I want to call this Javascript function

<div style="padding-left: 0px; color: #000; opacity: 0.8; cursor: pointer; font-size: 12px;
text-align: left; background-repeat: no-repeat; padding-left: 22px; background-image: url(<%=URL%>Resources/ws.img/liback.png);
background-repeat: no-repeat;" onclick='sendtopage(118,974);'> Planning Essentials</div>

-------------

On onclick on the that div the page is not doing anything. Becasue in javascript " location.href = Link.ToSubCategory(categoryId, subCategoryId); " has problem. Please help.

Kind regards
Nerd


Reply | Reply with attachment | Alert Moderator

 Responses below this adGet hundreds of .NET Tips and Tricks videos

  No reply found.


Reply - Please login to reply


Click here to login & reply

About Us | Contact Us | The Team | Advertise | Software Development | Write for us | Testimonials | Privacy Policy | Terms of Use | Link Exchange | Members | Go Top
General Notice: If you find plagiarised (copied) contents on this page, please let us know the original source along with your correct email id (to communicate) for further action.
Copyright © DotNetFunda.Com. All Rights Reserved. Copying or mimicking the site design and layout is prohibited. Logos, company names used here if any are only for reference purposes and they may be respective owner's right or trademarks. | 5/23/2013 5:37:42 PM