Simlpe Java Script question Re ApplicationPath

R

Radu

Hi. I have a page, named "SelectScorecard", which contains a combo
and some links to outside documents, on the server. These documents
are situated in some sub-folders of the webfolder, named "Previews"
and "BW Previews". On selection of an item in the combo, the HREF of
those links has to change.

In the SelectScorecard.aspx page, I have the code:

<script language="javascript">
function previewFile(cbo)
{
var index = cbo.selectedIndex;
var ifr = document.getElementById('<%=frameDocPreview.ClientID
%>');
var hLink = document.getElementById('<%=cmdOpenPreview.ClientID
%>');
var hLinkBW = document.getElementById('<%=cmdSupporting.ClientID
%>');

// first item is ' please select...'
if (index > 0)
{
ifr.src = 'preview.aspx?file=' +
escape(cbo.options[index].text);
hLink.href='<%=request.ApplicationPath %>'+ "/Previews/"+
cbo.options[index].text + ".doc";
hLinkBW.href='<%=request.ApplicationPath %>'+ "/BW Previews/"+
cbo.options[index].text + ".doc"
}
else
{
ifr.src = "#";
hLink.href="#";
hLinkBW.href="#"
}
document.getElementById('cmdNextPage').focus;
}
</script>


The hyperlinks themselves are defined in that page as:

<asp:HyperLink
ID="cmdOpenPreview"
Font-Size="11px"
Target="_blank"
Text="here"
runat="server">
</asp:HyperLink>

and

<asp:HyperLink
ID="cmdSupporting"
Font-Size="11px"
Target="_blank"
Text="here"
runat="server">
</asp:HyperLink>

The problem is that it works great on my machine.... On the DEV
server, though, upon selection of an item in the combo, HREF goes from
http://uat.mysite.com/Step 1 - SelectScorecard.aspx#
to
http://scorecard previews/Operations.doc
thus, obviously, missing the ApplicationPath part, as opposed to the
instance on my machine, which reads
http://localhost:1218/Ordering Process/Scorecard Previews/Us Operations.doc
which correctly points to the app path in addition to the "Previews"
folder and the selected (in this case, "US Operations") document.

So.... What's wrong with my script, saying
hLink.href='<%=request.ApplicationPath %>'+ "/Previews/"+
cbo.options[index].text + ".doc";

On the server, it picks up only the
"/Previews/"+ cbo.options[index].text + ".doc"
part, whereas on my dev machine it works great.

Thanks a lot for your reading this post.
Alex.
 
R

Rick Strahl [MVP]

Request.ApplicationPath should always be accessible as long as you're
running ASP.NET <s>. Are you sure the page is being processed by ASP.NET?

Are the ClientIds properly expanding on the problem app?

You can also use <%= Page.ResolvePath("~/somepage.aspx") %> to get a URL
that contains the basepath which is typically the approach to generate URLs
properly because it takes into account ASP.NET's own url processing (such as
cookieless sessions etc).

Also if your page language is C# make sure you use Request.ApplicationPath
(case sensitive!) but I think that's not your problem as you'd get an error
during page compilation.

+++ Rick ---

--

Rick Strahl
West Wind Technologies
www.west-wind.com/weblog


Radu said:
Hi. I have a page, named "SelectScorecard", which contains a combo
and some links to outside documents, on the server. These documents
are situated in some sub-folders of the webfolder, named "Previews"
and "BW Previews". On selection of an item in the combo, the HREF of
those links has to change.

In the SelectScorecard.aspx page, I have the code:

<script language="javascript">
function previewFile(cbo)
{
var index = cbo.selectedIndex;
var ifr = document.getElementById('<%=frameDocPreview.ClientID
%>');
var hLink = document.getElementById('<%=cmdOpenPreview.ClientID
%>');
var hLinkBW = document.getElementById('<%=cmdSupporting.ClientID
%>');

// first item is ' please select...'
if (index > 0)
{
ifr.src = 'preview.aspx?file=' +
escape(cbo.options[index].text);
hLink.href='<%=request.ApplicationPath %>'+ "/Previews/"+
cbo.options[index].text + ".doc";
hLinkBW.href='<%=request.ApplicationPath %>'+ "/BW Previews/"+
cbo.options[index].text + ".doc"
}
else
{
ifr.src = "#";
hLink.href="#";
hLinkBW.href="#"
}
document.getElementById('cmdNextPage').focus;
}
</script>


The hyperlinks themselves are defined in that page as:

<asp:HyperLink
ID="cmdOpenPreview"
Font-Size="11px"
Target="_blank"
Text="here"
runat="server">
</asp:HyperLink>

and

<asp:HyperLink
ID="cmdSupporting"
Font-Size="11px"
Target="_blank"
Text="here"
runat="server">
</asp:HyperLink>

The problem is that it works great on my machine.... On the DEV
server, though, upon selection of an item in the combo, HREF goes from
http://uat.mysite.com/Step 1 - SelectScorecard.aspx#
to
http://scorecard previews/Operations.doc
thus, obviously, missing the ApplicationPath part, as opposed to the
instance on my machine, which reads
http://localhost:1218/Ordering Process/Scorecard Previews/Us Operations.doc
which correctly points to the app path in addition to the "Previews"
folder and the selected (in this case, "US Operations") document.

So.... What's wrong with my script, saying
hLink.href='<%=request.ApplicationPath %>'+ "/Previews/"+
cbo.options[index].text + ".doc";

On the server, it picks up only the
"/Previews/"+ cbo.options[index].text + ".doc"
part, whereas on my dev machine it works great.

Thanks a lot for your reading this post.
Alex.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,773
Messages
2,569,594
Members
45,123
Latest member
Layne6498
Top