.NETGURU
ASP.NET control problem (path reference)
Messages   Related Types
This message was discovered on ASPFriends.com 'aspngclient' list.
Responses highlighted in red are from those people who are likely to be able to contribute good, authoratitive information to this discussion. They include Microsoft employees, MVP's and others who IMHO contribute well to these kinds of discussions.

Greg Huber
-- Moved from [aspngfreeforall] to [aspngclient] by Tim Musschoot <Click here to reveal e-mail address> --

I have an ASP.NET user control that includes some javascript. The control
file (ascx) and javascript file (.js) are both in the same path. However,
when I have an ASPX page in a different directory that uses the control, the
javascript doesn't get referenced properly (I'm guessing that the control is
trying to load the javascript relative to the ASPX page that calls it).
Here is some code from the user control:

<%@ Control Language="vb" AutoEventWireup="false" Codebehind="Title.ascx.vb"
Inherits="presto.Title"
TargetSchema="http://schemas.microsoft.com/intellisense/ie5"; %>
<script language="javascript" src="title.js"></script>

I can put the full path to the application in the src attribute and that
will work, but that means I have the absolute path which I don't want. Or,
I could simply put the .js file in the control. But I don't want that
either. Is there any other way to get this to work (ie- something that says
include this file from the controls directory, no matter where the control
is getting called from)?

Thanks,
    Greg

Reply to this message...
 
    
Dot Net Guru Serdar
You could declare a public variable in the ascx file that gets set during
the onload of each of the parent pages like so.

'in your user control code behind
Public javaSource As String
Protected javaString As System.Web.UI.WebControls.Literal

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
    If Not IsPostBack Then
        javaString.Text = "<script langugage=""javascript"" src="""
& javaSource & """></script>"
    End If
End Sub

'in your user control front end
<html>
<head>
<title>WebForm1</title>
</head>
<body>
<asp:literal id="javaString" runat="server"></asp:literal>
<form>
</form>
</body>
</html>

'in your parent page
Protected myControl As MyControlPage

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
    If Not IsPostBack Then
        myControl.javaSource = "../includes/java.js"
    End If
End Sub

hth

matt

-----Original Message-----
From: Greg Huber [mailto:Click here to reveal e-mail address]
Sent: Thursday, July 18, 2002 10:18 AM
To: aspngclient
Subject: [aspngclient] ASP.NET control problem (path reference)

-- Moved from [aspngfreeforall] to [aspngclient] by Tim Musschoot
<Click here to reveal e-mail address> --

I have an ASP.NET user control that includes some javascript. The control
file (ascx) and javascript file (.js) are both in the same path. However,
when I have an ASPX page in a different directory that uses the control, the
javascript doesn't get referenced properly (I'm guessing that the control is
trying to load the javascript relative to the ASPX page that calls it).
Here is some code from the user control:

<%@ Control Language="vb" AutoEventWireup="false" Codebehind="Title.ascx.vb"
Inherits="presto.Title"
TargetSchema="http://schemas.microsoft.com/intellisense/ie5"; %>
<script language="javascript" src="title.js"></script>

I can put the full path to the application in the src attribute and that
will work, but that means I have the absolute path which I don't want. Or,
I could simply put the .js file in the control. But I don't want that
either. Is there any other way to get this to work (ie- something that says
include this file from the controls directory, no matter where the control
is getting called from)?

Thanks,
    Greg
| [aspngclient] member Click here to reveal e-mail address = YOUR ID
| http://www.aspfriends.com/aspfriends/aspngclient.asp = JOIN/QUIT

Reply to this message...
 
    
Strauss, Jon (VIP)
Another approach is for each app directory to have a sub-virtual directory that points to a common virtual directory. The common virtual directory would contain your ascx and javascript files. Then you could always reference the files the same way, regardless of application. Something like this...

/IncludeDir        #store ascx and js file here
/App1/IncludeDir #points to /IncludeDir
/App2/IncludeDir    #points to /IncludeDir
/App3/IncludeDir    #points to /IncludeDir

Steve Smith has an article that explains this at:

http://www.aspalliance.com/stevesmith/articles/netreuse1.asp

Hope that helps,
Jon

[Original message clipped]

Reply to this message...
 
 
System.EventArgs
System.Object
System.Web.UI.WebControls.Literal




ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
Ad


Need Dot Net Interview Questions?
Ask ExamGuru, Inc. for advice and help on Passing .Net Interviews
.Net Projects
Best-of-breed application framework for .NET projects, developed by ExamGuru, Inc. and ExamGuru IT
Free .net Help
Commission ExamGuru, Inc. and his team for your next bespoke software project
FogBUGZ
The only bug tracking system carefully crafted with one goal in mind: helping teams create great software.
Awesome Tools
If you don't know about these, you're missing out... IT Certification Questions
IT Interview Questions
Free Oracle 10g Training
MCSE Boortcamp
Cisco Study Guides
Cheap Study Guides
Exact Questions
Dot Net Interview Questions
Oracle OCP
Cheap Travel
Designer Perfumes - Wholesale Prices
Free Programming Tutorials
 
ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
 Copyright © ExamGuru, Inc. 2001-2006
Contact Us - Terms of Use - Privacy Policy - www.dot-net-guru.com - www.examguru.net - www.oraclesource.net - www.itinterviews.net - www.examguru.net/ITCertification