hi,
how is it possible to reference another assebly from an aspx file? i am writing the aspx file in notepad
thanks in advance
Printable View
hi,
how is it possible to reference another assebly from an aspx file? i am writing the aspx file in notepad
thanks in advance
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
...and compiled it with this:PHP Code:using System;
namespace Samples
{
public class MySample
{
public DateTime GetDate()
{
return DateTime.Now;
}
}
}
used this aspx file Samples.aspx:Code:csc /t:library /out:MySample.dll /r:System.dll MySample.cs
copied the aspx file to my local webserver's root directory and the dll to bin directory of the local webserver.PHP Code:<%@ 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>
If you're using code behind concept then your code behind file might look like this, Samples.aspx.cs:
the aspx page would then look like this:PHP Code: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");
}
}
}
compile the web app like this:Code:<%@ Page Language="C#" Inherits="MyWeb.Samples" %>
<html>
<body>
<form runat="server">
<asp:Label ID="lblDateTime" Runat="server"/>
</form>
</body>
</html>
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.Code:csc /t:library /out:MyWeb.dll /r:System.dll /r:System.Web.dll /r:MySample.dll Samples.aspx.cs