PDA

Click to See Complete Forum and Search --> : referencing???!


persianboy
Nov 22nd, 2003, 01:06 AM
hi,

how is it possible to reference another assebly from an aspx file? i am writing the aspx file in notepad

thanks in advance

pvb
Nov 24th, 2003, 08:22 PM
If you stick the other dll in the bin directory, you can import the namespace in an <%@ Import Namespace %> block at the top of the aspx page.
Just to make sure I'm not lying I tried it out with notepad. Here's the source of the other dll:
MySample.cs
using System;
namespace Samples
{
public class MySample
{
public DateTime GetDate()
{
return DateTime.Now;
}
}
}
...and compiled it with this:
csc /t:library /out:MySample.dll /r:System.dll MySample.cs
used this aspx file Samples.aspx:
<%@ Import Namespace="Samples" %>
<script language="c#" runat="server">
override protected void OnInit(System.EventArgs e)
{
base.OnInit(e);
MySample m = new MySample();
lblDateTime.Text = m.GetDate().ToString("MM/dd/yyyy hh:mm");
}
</script>
<html>
<body>
<form runat="server">
<asp:Label ID="lblDateTime" Runat="server"/>
</form>
</body>
</html>
copied the aspx file to my local webserver's root directory and the dll to bin directory of the local webserver.

If you're using code behind concept then your code behind file might look like this, Samples.aspx.cs:
using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using Samples;

namespace MyWeb
{
public class Samples : System.Web.UI.Page
{
protected Label lblDateTime;
protected override void OnInit(System.EventArgs e)
{
base.OnInit(e);
MySample m = new MySample();
lblDateTime.Text = m.GetDate().ToString("MM/dd/yyyy hh:mm");
}
}
}

the aspx page would then look like this:
<%@ Page Language="C#" Inherits="MyWeb.Samples" %>
<html>
<body>
<form runat="server">
<asp:Label ID="lblDateTime" Runat="server"/>
</form>
</body>
</html>

compile the web app like this:
csc /t:library /out:MyWeb.dll /r:System.dll /r:System.Web.dll /r:MySample.dll Samples.aspx.cs

copy the MyWeb.dll to the bin directory of the webserver you're using and the aspx page to the root directory or whereever and you're done.