Can you share a code behind file with a page and usercontrol?

M

Michael Evanchik

Tying not to spaghetti code which seems to be easy to do in .net, im
trying to do my main .net html in index.aspx, use repeated .net html
in an .ascx files and all code im doing in .vb code behind files.

I have no problem using my .vb code behind file for my .aspx pages i
just have to say <%@ Page Language="vb" Inherits="myCode"
src="index.vb" %> in my aspx file and use Inherits Page in my .vb code
behind file and everything is cool

What do you do for .ascx pages(usercontrols) to share the SAME .vb
file?? I have tried to add inherits UserControl but only one inherit
is allowed at a time. Thanks for your help.

Mike
 
M

Michael Evanchik

I was able to do it. Im not sure Marina if my question was even clear
but here is the code I came up with. I can now use the same
codebehind file for an aspx an ascx just referencing the different
class names

codebehind.vb
-------------------
Public Class myCode2
Inherits UserControl
Public WithEvents clsit As New myCode()

sub new_agent(sender As Object, e As System.EventArgs)
dim scalar as string
scalar = clsit.sql_scalar("select cust_name from customers")
end sub

End Class


Public Class myCode
Inherits Page
Function sql_scalar(ByVal str As String) As String
cmd = New OleDbCommand(str, conn)
Return cmd.ExecuteScalar()
End Function
End Class
 

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

Members online

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top