Results 1 to 2 of 2

Thread: referencing???!

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Sep 2003
    Posts
    227

    referencing???!

    hi,

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

    thanks in advance

  2. #2
    Hyperactive Member
    Join Date
    Aug 2002
    Location
    Fort Collins, CO
    Posts
    366
    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
    PHP Code:
    using System;
    namespace 
    Samples
    {
        public class 
    MySample
        
    {
            public 
    DateTime GetDate()
            {
                return 
    DateTime.Now;
            }
        }

    ...and compiled it with this:
    Code:
    csc /t:library /out:MySample.dll /r:System.dll MySample.cs
    used this aspx file Samples.aspx:
    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
    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:
    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");
            }
        }

    the aspx page would then look like this:
    Code:
    <%@ 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:
    Code:
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width