Calling .vb from .aspx

netherfear

New Member
I am using some client side controls and need to call my vb code behind subs from the .aspx page. I am a vb programmer and dont know the limitations of asp or the best way to do things at this point. If I use server controls I dont have a problem except that I cant capture events. If I cant call the code behind how can I import the system.data.sqlclient into the .aspx page so I can use a dataset from there?I would suggest you to read the following 7 part articles on databases. the location is http://www.aspalliance.com/wisemonk/<BR><BR>You will learn all about accessing databases from the .aspx page. But it does not use code behind techique which you have asked for. For a basic understanding of how code behind works<BR>see the following:<BR><BR>helloworld.aspx<BR><BR><%@ Page Language="vb" Codebehind="helloworld.aspx.vb" Inherits="HelloWorld"%><BR><html><BR> <head><BR> <title></title><BR> </head><BR> <body><BR> <form id="Form1" method="post" runat="server"><BR> <asp:TextBox id="txtDisplay" Runat="server"></asp:TextBox><BR> <asp:Button Text="Show" onClick="Show_Click" Runat="server"></asp:Button><BR> </form><BR> </body><BR></html><BR><BR>helloworld.aspx.vb<BR><BR>Public Class HelloWorld<BR><BR> Inherits System.Web.UI.Page<BR> Protected WithEvents txtDisplay As System.Web.UI.WebControls.TextBox<BR><BR> Public Sub Show_Click(ByVal sender As Object, ByVal e As EventArgs)<BR> txtDisplay.Text = "Hello World"<BR> End Sub<BR><BR>End Class<BR><BR>In the above example you can see I am displaying the hello world message from the code behind. Likewise for the database you need to place data controls onto your .aspx page and write code in the codebehind and assign the results to the data control you have placed on the .aspx It is as easy as that. But using databases in .net framework is a massive ocean, so you need to learn all about databases before you jump to code behind techniques.<BR><BR>cheers<BR>dotnetlover (sunny)Did this code work on your machine? For some reason I can't get it to run. It cant't seem to find the code in the code behind.When you use the <BR><BR><%@ page inherits="namespace.class" %><BR><BR>The namespace.class part is case-sensitive. I nearly threw my computer out the window the other day because of it. This is why even though vb isnt case-sensitive its never a bad idea to "think" case-sensitive.<BR><BR>Hope that helps.Maybe its just me but every since I started working with .net, I feel like I should be riding the short bus to work. Everything is "right" to the best of my knowledge and I still can't reference the .vb from my .aspx page. I get a type mismatch on whatever procedure I am trying to call.I dont think its possible to access a variable or function from a base class unless you mark it as overridable and override it. The whole purpose of using codebehind is so you keep everything out of the .aspx page. Only code in aspx page should be<BR><BR><%@ Page inherits="blah" src=http://aspmessageboard.com/archive/index.php/"blah" %><BR><BR>The rest should be your user interface. <BR><BR>You have to define all variables that are controls on your aspx page as public in your code behind. Then simply put any logic you need inside the codebehind file. Ive gone over this in my head a few times. Ive come to the conclusion there is no reason that every page shouldnt use codebehind. Even if there is a seperate vb file for every aspx page ( well unless the .aspx page only has like page_load event or something ) It keeps code neatly seperated and teaches the importance of inheritence and code reuse.I think I finally figured it out...Thanks everyone.I was just having a hard time capturing events. Being a vb programmer I am used to event driven programming. I dont want ot have to push a button to make things happen. What ever happend to text1_LostFocus? That was easy. Now I have to work twice as hard to capture events without posting back to the server. I have found client controls easier to work with capturing events. I just found out that if you look at the source code behind the webpage it takes out all the server stuff anyway. You can ignore some of the errors in .net and by the time it gets on the page it will run fine.yes, it did work on my machine.
 
Back
Top