Javascript - masterpage - help

Last post 11-29-2005 6:09 PM by kashif. 1 replies.

Sort Posts:

  • Embarrassed [:$] Javascript - masterpage - help

    11-21-2005, 3:08 PM
    • Member
      750 point Member
    • fzilz
    • Member since 03-06-2003, 10:35 AM
    • Benicia, CA
    • Posts 150
    I am trying to convert my asp.net 1.1 website to an asp.net 2.0.  All is going well, accept I can not figure out how to get my navigation, images and links to work.

    an excerpt of my master page is this:

    <code>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    <scrit language="JavaScript">

    <!--

    function MM_swapImgRestore() { //v3.0

    var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;

    }

    function MM_preloadImages() { //v3.0

    var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();

    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)

    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}

    }

    function MM_findObj(n, d) { //v4.0

    var p,i,x; if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {

    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}

    if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];

    for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);

    if(!x && document.getElementById) x=document.getElementById(n); return x;

    }

    function MM_swapImage() { //v3.0

    var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)

    if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}

    }

    //-->

    </scrit>

    <html xmlns="http://www.w3.org/1999/xhtml" >

    <head runat="server">

    <title>InterHealth Nutraceuticals</title>

    <link rel="stylesheet" type="text/css" href="../images/ihstyle.css" />

    </head>

    <body>

    <form id="form1" runat="server">

    <div>

    <table width="752" border="0" cellspacing="0" cellpadding="0" >

    <tr valign="top">

    <td colspan="2" height="105" background="../images/top_border.jpg">

    <table width="600" border="0" cellspacing="0" cellpadding="0">

    <tr valign="top">

    <td width="150" height="75"><a href="default2.aspx" ><img src="../images/ih_logo3.jpg" width="147" height="68" border="0" alt="Home" ></a></td>

    <td colspan="7" align="right" valign="middle" height="75">&nbsp;</td>

    </tr>

    </table>

    </td>

    </tr>

    <tr>

    <td width="110" valign=top><div id=divbody onLoad="MM_preloadimages('../images/aboutus2.gif','../images/products2.gif','../images/research2.gif','../images/news2.gif','../images/contact2.gif')">

    <table id="Table1" width="100" border="0" cellspacing="0" cellpadding="0" align="left" background="../images/left_Border.jpg" ><tr><td><table id="Table2" width="92" border="0" cellspacing="0" cellpadding="0" align="center" runat="server">

    <tr>

    <td valign="top" align="center" >&nbsp;</td>

    </tr><tr>

    <td valign="top" align="center" >&nbsp;</td>

    </tr>

    <tr>

    <td valign="top" align="center" >&nbsp;</td>

    </tr>

    <tr>

    <td valign="top" align="left" height="7">

    <p><font size="1" face="Arial, Helvetica, sans-serif" color="#FFFFFF"><a href="../aboutus/aboutus.aspx" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('About Us','','../images/aboutus2.gif',1)" target="_self"><img name="About Us" border="0" src="../images/aboutus1.gif" width="87" height="16"></a></font></p>

    </td>

    </tr>

    <tr>

    <td valign="top" height="2" align="left" ><img src="../images/mid1.gif" width="87" height="2"></td>

    </tr>


    ......
    </code>

    My website structure is such that some of my pages that use the master are at the root of my website and some are one folder down.   I have tried replacing ../ with ~/ but this does not seem to work.  My links show up in my webpage as http://website/~/images/image.gif.  For the static images, I can change the images to server controls and then the ~ substitution works.  But for my rollover images, and my html table and table cell background images, how do I get the relative links to work.  Why am I having this issue, when I did not before.  Is it the xhtml transitional or the asp.net 2.0 upgrade that is causing the issue?

    Thanks for your assistance.  I feel really stupid that I can not figure out how to get relative links to work correctly.
  • Re: Javascript - masterpage - help

    11-29-2005, 6:09 PM
    • Contributor
      2,738 point Contributor
    • kashif
    • Member since 06-11-2002, 9:34 AM
    • Posts 547
    • AspNetTeam
      Moderator

    For non-serverside controls which reference an url - you can use the ResolveClientUrl() function to ensure that the path is rooted correctly for the images link - something like <%# ResolveClientUrl("~/images/foo.gif") %> and call DataBind() on the page.

    Hope that helps,
    Kashif

Page 1 of 1 (2 items)