import of dynamic class file

S

s.hong

Hello?

On the ASP.NET, I can use the class by import declation on the top of page.

<%@ page language="vb" explicit="true" aspcompat="false" debug="true"%>
<%@ import namespace="System.Data" %>
<%@ import namespace="System.Data.SqlClient" %>

It's work well for the compiled class files in /bin folder.

But, I have a problem on using class file which are not complied.
How can I import or include it to asp.net source code?

For example. I have two class files written in vb.net.

student.aspx.vb
<script language="vb" runat="server">
public class Student
....
end class
</script>

teacher.aspx.vb
<script language="vb" runat="server">
public class Teacher
....
end class
</script>

If I try to include both class file to asp.net code.

<!-- #include file="student.aspx.vb" -->
<!-- #include file="teacher.aspx.vb" -->

It occur error that the definition of class was not founded on running.
If I merge the classfile to one file. then, It work well.
Is there are any method to use indivisual files on asp.net?

Hope for your kindly reply.

Thanks!
 
K

Karl Bauer

Hello,

You can use the @ Reference Directive in ASP.Net.
From the German .Net Framework Documentation:

<%@ Reference page | control="pathtofile" %>

Attribute
Page
Die Web Forms-Seite, die von ASP.NET zur Laufzeit dynamisch
kompiliert und mit der aktuellen Seite verknüpft werden soll.
Control
Das Benutzersteuerelement, das von ASP.NET zur Laufzeit dynamisch
kompiliert und mit der aktuellen Seite verknüpft werden soll.


C#]
<%@ Reference Control="MyControl.ascx" %>
<script language="C#" runat=server>

void Page_Load(Object sender, EventArgs e) {

// In the @ Control directive in the MyControl.ascx file,
// you must include classname="MyControl" for this to work.
MyControl myControl = (MyControl)
Page.LoadControl("MyControl.ascx");
myControl.MyProperty = "Color";

PlaceHolder.Controls.Add(myControl);
}

</script>

<html>
<body>
<asp:placeholder id="PlaceHolder" runat=server/>
</body>
</html>


Hope this helps!
schorsch
 
S

s.hong

Thanks Karl,

I succeed to use the class files on my asp.net page.
But, It's needed to generate ascx files for each class file to use
@Reference derective.

Thank you very much!

Karl Bauer said:
Hello,

You can use the @ Reference Directive in ASP.Net.
From the German .Net Framework Documentation:

<%@ Reference page | control="pathtofile" %>

Attribute
Page
Die Web Forms-Seite, die von ASP.NET zur Laufzeit dynamisch
kompiliert und mit der aktuellen Seite verknüpft werden soll.
Control
Das Benutzersteuerelement, das von ASP.NET zur Laufzeit dynamisch
kompiliert und mit der aktuellen Seite verknüpft werden soll.


C#]
<%@ Reference Control="MyControl.ascx" %>
<script language="C#" runat=server>

void Page_Load(Object sender, EventArgs e) {

// In the @ Control directive in the MyControl.ascx file,
// you must include classname="MyControl" for this to work.
MyControl myControl = (MyControl)
Page.LoadControl("MyControl.ascx");
myControl.MyProperty = "Color";

PlaceHolder.Controls.Add(myControl);
}

</script>

<html>
<body>
<asp:placeholder id="PlaceHolder" runat=server/>
</body>
</html>


Hope this helps!
schorsch



Hello?

On the ASP.NET, I can use the class by import declation on the top of page.

<%@ page language="vb" explicit="true" aspcompat="false" debug="true"%>
<%@ import namespace="System.Data" %>
<%@ import namespace="System.Data.SqlClient" %>

It's work well for the compiled class files in /bin folder.

But, I have a problem on using class file which are not complied.
How can I import or include it to asp.net source code?

For example. I have two class files written in vb.net.

student.aspx.vb
<script language="vb" runat="server">
public class Student
....
end class
</script>

teacher.aspx.vb
<script language="vb" runat="server">
public class Teacher
....
end class
</script>

If I try to include both class file to asp.net code.

<!-- #include file="student.aspx.vb" -->
<!-- #include file="teacher.aspx.vb" -->

It occur error that the definition of class was not founded on running.
If I merge the classfile to one file. then, It work well.
Is there are any method to use indivisual files on asp.net?

Hope for your kindly reply.

Thanks!
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top