473,769 Members | 6,208 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Using Codebehind

Hi. I've just started my second ASP.NET (VB) app and I'm using
codebehind this time.

I'm not using visual studio but am instead coding it all in notepad
(HTML, ASP.NET and CSS)

I'm trying to understand how to best use codebehind to do what I want
to achieve. Basically, so far I have a codebehind file for one page
which works as I wanted but I want other pages to share that
codebehind file. That's no problem except I want each one to use
there own Page_Load subroutine in the codebehind and to share some
sub's.

The only way I think might work would be to use different classes
within the codebehind file. I did consider two codebehind files I
couldn't inherit them both. I'm not sure how the classes work exactly
and I have no idea if I can pass variables between them and call subs
from one class into another!

I'm really after some information on how to use the classes /
codebehind to allow me to have page specific subroutines and shared
subroutines within one or more codebehind file.

Any advice welcomed to help me learn this a bit better will be
appriciated

Thanks,

Steve

----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeed.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption =---
Nov 18 '05 #1
3 1588
You need to think object-oriented here, and I think you would benefit from a
bit of study regarding object-oriented programming, particularly with
regards to inheritance. In classic ASP, you would think of files. In
ASP.Net, you work with files at design-time for writing code, but it is best
not to think about the files, but rather, to think about classes. An ASP.Net
Page is derived from combining a Page class definition (CodeBehind) with a
Page Template that inherits that class. By inherits, I mean that it has all
the properties, methods, fields, event handlers, etc., that the CodeBehind
class has, as well as the pieces of the Page class that are defined via the
Template code. This is an important distinction. So, rather than referring
to the "CodeBehind file" you will find it much easier to conceive of this by
referring to it as the "CodeBehind Class." When you think of it in this way,
you can see that putting 2 different Page class definitions in one
CodeBehind file accomplishes nothing, as they are still 2 distinct classes,
and share nothing in common.

Any number of Page Templates can inherit the same CodeBehind class. However,
it gets a bit tricky because of the separation of the 2 pieces. For example,
if you include any Server Controls in the Page Template, and you want to be
able to manipulate them programmaticall y in the CodeBehind class, there
needs to be a declaration of the Control's class in the CodeBehind.

In fact, you didn't state what your business requirements are, but I suspect
that what you want could be much better accomplished in some other way. For
example, if you have business logic that you want shared between Pages, put
it into an Assembly (DLL) which all pages can use. If you have some layout
elements that you want to share betwen pages, you can either create User
Controls that you use in all pages, or use CSS to do your layout. CSS is
very powerful, and can be used to do nearly all the layout-related
customization of a site. A good reference for using CSS in this way can be
found at http://csszengarden.com/. One advantage of using CSS is that you
can separate your layout from your interface logic very neatly in this way.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.
"nevets2001 uk" <st****@gordonb ase.freeserve.c o-dot-uk.no-spam.invalid> wrote
in message news:40******** **@127.0.0.1...
Hi. I've just started my second ASP.NET (VB) app and I'm using
codebehind this time.

I'm not using visual studio but am instead coding it all in notepad
(HTML, ASP.NET and CSS)

I'm trying to understand how to best use codebehind to do what I want
to achieve. Basically, so far I have a codebehind file for one page
which works as I wanted but I want other pages to share that
codebehind file. That's no problem except I want each one to use
there own Page_Load subroutine in the codebehind and to share some
sub's.

The only way I think might work would be to use different classes
within the codebehind file. I did consider two codebehind files I
couldn't inherit them both. I'm not sure how the classes work exactly
and I have no idea if I can pass variables between them and call subs
from one class into another!

I'm really after some information on how to use the classes /
codebehind to allow me to have page specific subroutines and shared
subroutines within one or more codebehind file.

Any advice welcomed to help me learn this a bit better will be
appriciated

Thanks,

Steve

----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==---- http://www.newsfeed.com The #1 Newsgroup Service in the World! >100,000 Newsgroups ---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption

=---
Nov 18 '05 #2
Thanks for your help. Do you know of any good links to help me with
things such as creating business logic in DLL's etc. Until recently I
was new to ASP.NET and have taught myself the basics as I go so any
tutorials that would help me would be great.

Cheers

Steve

----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeed.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption =---
Nov 18 '05 #3
That's a tough question to answer. The authoritative site is the Microsoft
MSDN web site (http://msdn.microsoft.com). The MSDN site has a number of
articles about Best Practices, Architecture, Design Patterns, etc. However,
Microsoft also runs http://www.asp.net, and there are a large number of
other sites out there with technical information, articles, and tutorials on
the subject.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.

"nevets2001 uk" <st****@gordonb ase.freeserve.c o-dot-uk.no-spam.invalid> wrote
in message news:40******** **@127.0.0.1...
Thanks for your help. Do you know of any good links to help me with
things such as creating business logic in DLL's etc. Until recently I
was new to ASP.NET and have taught myself the basics as I go so any
tutorials that would help me would be great.

Cheers

Steve

----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==---- http://www.newsfeed.com The #1 Newsgroup Service in the World! >100,000 Newsgroups ---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption

=---
Nov 18 '05 #4

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

Similar topics

43
2676
by: nospam | last post by:
I got three (3) files (1) Untitled.aspx (2) Untitled.aspx.1.cs (3) Untitled.aspx.2.cs These three files must be used together to make file #1, Untitled.aspx, page work via J.I.T. when the User first hits Internet Explorer 6.0 on your browser.
2
2886
by: Graham Allwood | last post by:
I'm reading the Essential ASP.NET book by Fritz onion and he says that when VS.NET creates a new .aspx page for you is uses the codebehind attribute on the Page directive rather than the src attribute. From what I understand the src attrib is standard ASP.NET but the codebehind attribute is only understood by VS.NET. Doesn't this make the pages (source code) less portable? Is there any reason for this? Hope someone can help.
0
2285
by: Dave | last post by:
Hi, I understand that the CodeBehind= is designed to be used by VS and not actually part of the .NET framework However, in my BenefitsVB project to test how the SRC works, I created a simple aspx and codebind (below) and added Src="WebFormSrc.aspx.vb" to the page directive. I then tried to browse the page and got:
6
1788
by: Nehal Shah | last post by:
I've read that in the Page Directive of an aspx page, changing the CodeBehind attribute to Src saves you from having to compile the page before refreshing. This is preferable in a large development environment where rather than having each developer running a local copy of a website, they can make changes simultaneously to a central web server without stepping on each other's toes as far as compilation is concerned. ANYWAY, this is fine...
2
5174
by: Bart Adriaanse | last post by:
As VS.NET is not being very supportive in creating a ASHX http handler, i would like to use a codebehind VB file as to get intellisense features etc on it's code. I just cannot get ashx to work with codebehind, the only reference claiming it can be done i could find in google is this: http://weblogs.asp.net/kdente/posts/10622.aspx I tried using the class name as suggested, to no avail...
12
1653
by: Karl Hungus | last post by:
If I use a code behind class for an aspx page, what is the best way to get data from the codebehind class into my aspx page? I know about databinding, but is there a more basic way of just referencing the variables or calling getters? thanks in advance
6
3426
by: Anders M | last post by:
I'm trying to use Inline-code to call Page_load, Page_Init or Page_PreRender methods. I've also got a code behind c#-file. I can define inline methods for buttons and so on...that works fine. But when I try to call Page_load, Page_Init or Page_PreRender methods it doesn't work. Non of the methods get's triggered !?
3
1706
by: ABC | last post by:
How to create a web page class for inhert web page using ASP.NET 1.1 and 2.0?
10
1822
by: janisgs | last post by:
Hi Is there a way to seperate code of interface in windows applications for various design purposes? Just like it can be done in ASP.NET, one code can be inherited in different skins with different design. Sincerely Del
0
9587
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10211
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10045
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9863
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8870
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6672
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5298
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5447
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3958
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.