Link build through a class and get that in online code

Posted by Nerdanalysis under C# on 5/9/2012 | Points: 10 | Views : 877 | Status : [Member] | Replies : 0
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));
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) {

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


(No response found.)

Login to post response