Reference .cs File From .cs File

Discussion in 'ASP .Net' started by David, Apr 16, 2004.

  1. David

    David Guest

    I have two classes and a web page: test1.cs, test2.cs, and test.aspx.
    I know how to add a reference to test1.cs from test.aspx using the
    assembly directive (<%@ Assembly Src="test1.cs" %>). This works fine,
    but what if test1.cs needs to call a method from test2.cs. How can I
    add a reference to test2.cs from test1.cs without compiling either?

    --------test.aspx--------
    <%@ Page Language="C#"%>
    <%@ Assembly Src="test1.cs" %>
    <%@ Assembly Src="test2.cs" %>

    <script runat="server">
    void Page_Load() {
    Response.Write(ns1.ClassOne.SomeMethod());
    Response.Write("<br>");
    Response.Write(ns2.ClassTwo.AnotherMethod());
    }
    </script>


    --------test1.cs--------
    namespace ns1 {
    public class ClassOne {
    public static string SomeMethod() {
    return "return from SomeMethod class one";
    //How do I call AnotherMethod() from here???
    }
    }
    }


    --------test2.cs--------
    namespace ns2 {
    public class ClassTwo {
    public static string AnotherMethod() {
    return "return from AnotherMethod class two";
    }
    }
    }
     
    David, Apr 16, 2004
    #1
    1. Advertising

  2. David

    Curt_C [MVP] Guest

    inheritance

    --
    Curt Christianson
    Owner/Lead Developer, DF-Software
    www.Darkfalz.com


    "David" <> wrote in message
    news:...
    > I have two classes and a web page: test1.cs, test2.cs, and test.aspx.
    > I know how to add a reference to test1.cs from test.aspx using the
    > assembly directive (<%@ Assembly Src="test1.cs" %>). This works fine,
    > but what if test1.cs needs to call a method from test2.cs. How can I
    > add a reference to test2.cs from test1.cs without compiling either?
    >
    > --------test.aspx--------
    > <%@ Page Language="C#"%>
    > <%@ Assembly Src="test1.cs" %>
    > <%@ Assembly Src="test2.cs" %>
    >
    > <script runat="server">
    > void Page_Load() {
    > Response.Write(ns1.ClassOne.SomeMethod());
    > Response.Write("<br>");
    > Response.Write(ns2.ClassTwo.AnotherMethod());
    > }
    > </script>
    >
    >
    > --------test1.cs--------
    > namespace ns1 {
    > public class ClassOne {
    > public static string SomeMethod() {
    > return "return from SomeMethod class one";
    > //How do I call AnotherMethod() from here???
    > }
    > }
    > }
    >
    >
    > --------test2.cs--------
    > namespace ns2 {
    > public class ClassTwo {
    > public static string AnotherMethod() {
    > return "return from AnotherMethod class two";
    > }
    > }
    > }
     
    Curt_C [MVP], Apr 16, 2004
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Darren
    Replies:
    0
    Views:
    510
    Darren
    Oct 11, 2004
  2. Dude
    Replies:
    0
    Views:
    364
  3. ce
    Replies:
    1
    Views:
    3,005
  4. sam pal
    Replies:
    3
    Views:
    566
    E. Robert Tisdale
    Jul 16, 2003
  5. Craig Nicol
    Replies:
    2
    Views:
    471
    Craig Nicol
    May 10, 2004
Loading...

Share This Page