473,434 Members | 1,820 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,434 software developers and data experts.

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

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
Nov 17 '05 #1
1 2879
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
"Marina" <mz*******@hotmail.com> wrote in message news:<#J**************@tk2msftngp13.phx.gbl>...
No, you cannot.

A .aspx by default inherits from Page, or another descendent of Page. And a
user control does the same with UserControl.

However, they both inherit from TemplateControl. So, you can try having
your one .vb file inherit from TemplateControl instead of either Page or
UserControl. Not sure if this will work, especially with the designer.
Also, you may have to modify your code, if you are relying on Page or
UserControl specific methods or properties.

"Michael Evanchik" <mc****@aol.com> wrote in message
news:73**************************@posting.google.c om...
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

Nov 17 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Wysiwyg | last post by:
I'm new to c# programming and can't figure out how to avoid duplicating common code in multiple classes when I'm restricted to using different system base classes.. I'm using c# in asp.net to write...
4
by: Mark Friedman | last post by:
I can't seem to figure out how to get a reference to a UserControl in the code-behind for the page that contains the control. All the examples I've seen show how to pass property values from the...
6
by: William Parker | last post by:
I have a web control I made called header.ascx. It has its own properties and methods I defined. But I cannot figure out how to access this control from my code behind page. I can create the...
2
by: Ric | last post by:
im new to asp.net. from what i understand, you have the aspx file (presentation), user-control(ascx file), code-behind(vb file) and components(compiled vb and dll files). the aspx file contains a...
11
by: Daniel Manes | last post by:
Okay, here are the facts ma'am (or mister): 1. I have a user control called "Header" and a main page called "ReportMatch". 2. I've written "code-behinds" for both the user control and the main...
2
by: N. Demos | last post by:
I have a user control with code behind of which two instances are created/declared in my aspx page. The aspx page has code behind also, as I need to access methods of the usercontrols on page...
3
by: Alan Silver | last post by:
Hello, I have a set of user controls that all use the same code-behind file. The first line of each of the ascx files looks like... <%@ CodeFile="ShowCategory.cs" Language="C#"...
9
by: Alan Silver | last post by:
Hello, I have a user control which I am trying to load dynamically, but am running into problems. I think the problem is because I have two .ascx files that refer to the same .ascx.cs file. A...
2
by: rn5a | last post by:
Assume that a user control (MyUC.ascx) encapsulates 2 TextBoxes with the IDs 'txt1' & 'txt2' respectively. To use this user control in an ASPX page, the following Register directive will be...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.