Search:
Namespaces
Discussions
.NET v1.1
Feedback
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...
Matt 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
Ad
MBR BootFX
Best-of-breed application framework for .NET projects, developed by Matthew Baxter-Reynolds and MBR IT
Copyright © Matthew Baxter-Reynolds 2001-2008. '.NET 247 Software Development Services' is a trading style of MBR IT Solutions Ltd.
Contact Us
-
Terms of Use
-
Privacy Policy
-
www.dotnet247.com