I'm doing a quick port of an ASP.NET Web Application Project from 1.1 to 2.0. So, instead of a master page the template was created as a custom control. There is a search box in the side panel which is accessible from every page on the site. The panel contains two text boxes for first and second names.
On submitting the search params as query strings, the user is transferred to mysite.com/search/results.aspx. The problem is that depending on where the user submits the search from the path may come up as follows:
mysite.com**/dir1/dir2**/search/results.aspx
I need to resolve it from the root and it looks like the JS location object is the problem.
Here is the original code. How can I construct the link to resolve from the root?
rightGutter.Controls.Add(new LiteralControl("<script language=javascript>"));
rightGutter.Controls.Add(new LiteralControl
("function doPhoneSearch(txtval,txtVal1) {"));
rightGutter.Controls.Add
(new LiteralControl("location.replace
('search/results.aspx?lnamedpco=' + txtval+'&fname='+txtVal1);"));
rightGutter.Controls.Add(new LiteralControl("txtval=\"\";"));
rightGutter.Controls.Add(new LiteralControl("return false;"));
rightGutter.Controls.Add(new LiteralControl("}"));
rightGutter.Controls.Add(new LiteralControl("</script>"));
HtmlTableCell rightCell8 = new HtmlTableCell();
rightCell8.Attributes.Add("align", "right");
rightCell8.Controls.Add
(new LiteralControl
("<a onClick=\"doPhoneSearch(document.getElementsByName
('lnamedpco')[0].value,
document.getElementsByName('fname')[0].value)\">"));
Image bgImage5 = new Image();
bgImage5.ImageUrl = "~/images/gobtn.gif";
bgImage5.Attributes.Add("runat", "server");
rightCell8.Controls.Add(bgImage5);
rightCell8.Controls.Add(new LiteralControl("</a>"));
<a onClick=\"doPhoneSearch(document.getElementsByName('lnamedpco')[0].value,
document.getElementsByName('fname')[0].value)\">
<img SRC=\"http://mysite/images/gobtn.gif\"
BORDER=\"0\" ALT=\"Submit Form\">
</a>