Jump to content

Calling one VB.NET script from another


kwilliams

Recommended Posts

I'm a newbie to VB.NET, and I need to know how to call code from an external VB.NET file from within method body. I was thinking something like this:CODE:

<script runat="server">	Sub Page_Load(sender As Object, e As EventArgs)		'Code for this page		'...some code...		'Code from external VB.NET doc goes here - HOW???	End Sub</script>

EXTERNAL VB.NET DOC'S CODE:

Sub hello	headtitle.text = "HELLO WORLD!"End SubIf Not Page.IsPostBack Then	'...some code...End If

RESULTING CODE:

<script runat="server">	Sub Page_Load(sender As Object, e As EventArgs)		'Code for this page		'...some code...		'Code from external VB.NET doc		Sub hello			headtitle.text = "HELLO WORLD!"		End Sub		If Not Page.IsPostBack Then			'...some code...		End If	End Sub</script>

If anyone can show me how to do this, that would be great. Thanks.

Link to comment
Share on other sites

ASP.Net does still support SSI but recommends using OO style programming instead. This method requires compiling the class into a .dll file. If you are not using VS or do not want ot mess with batch files to get it compiled, you may be able to use <!-- #include file="external.vb" -->

Link to comment
Share on other sites

ASP.Net does still support SSI but recommends using OO style programming instead. This method requires compiling the class into a .dll file. If you are not using VS or do not want ot mess with batch files to get it compiled, you may be able to use <!-- #include file="external.vb" -->
But I need to include the external document's VB.NET code within the script tag, which I can't do with SSI's. I tried it just for the heck of it, and I received the following error:Parser Error Message: Server includes are not allowed in server script tags.I use Web Matrix for development, so I wouldn't know how to do the other suggestion. If you or anyone else has any other suggestions, I'd love to hear them. Thanks.
Link to comment
Share on other sites

Ok, I figured out how to do it as soon as I added my last post.This is the solution that worked for me:

<script runat="server">	Sub Page_Load(sender As Object, e As EventArgs)</script><script runat="server">	'Page code goes here</script><script language="vb" runat="server" src="external.vb" /><script runat="server">	End Sub</script>

And it worked! The change only resulted in the filesize being 142 bytes greater in size, but I'm not sure if doing it this way will cause any problems. If anyone knows whether or not it will cause problems, please let me know. Thanks.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...