kwilliams Posted September 8, 2006 Share Posted September 8, 2006 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 More sharing options...
aspnetguy Posted September 8, 2006 Share Posted September 8, 2006 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 More sharing options...
kwilliams Posted September 8, 2006 Author Share Posted September 8, 2006 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 More sharing options...
kwilliams Posted September 8, 2006 Author Share Posted September 8, 2006 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 More sharing options...
aspnetguy Posted September 8, 2006 Share Posted September 8, 2006 Glad it work although it a bit horrendous . Look into using classes to reuse code it is much cleaner and more effiencent Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now