Reusing Code

Z

Zodiac

Hi all,

I've been studying ASP.Net for a couple of weeks now.And it's starting to
come to me. For me the next step is trying to figure out what is the best
way to reuse code and webforms.

For example I wrote a logon page, in combination with a user management
page(edit, create, delete, password, ...). So when I start a new project in
wich I want to use these pages and the code behind modules i want to off
course reuse these pages. How can I accomplish this the best? Are there any
tutorials or explanations available about this?

rgds,

Z.
 
E

Eliyahu Goldin

In ASP.NET 2.0 there are Master Pages. In 1.1 you don't have many options.
There is no visual inheritance for pages. You can make user controls if you
find it appropriate. In most of the cases you will just cut and paste.

Eliyahu
 
K

Karl Seguin

Your best friend when it comes to code reuse is having a solid NTier
architecture and taking advantage of OO capabilities.

In your case this should mean that all the logic to edit, create, delete,
password should be in a separate class which you can simply reference from
any project.

As far as actually reusing visual components across projects, your only real
alternative is to create Server Controls which I personally find too
complicated except for in the most simple cases. Within projects you can
make use of far simpler UserControls and things such as MasterPages (which
Eliyahu talked about). MetaBuilders have a great free masterpage control
for ASP.NEt 1.1 (http://www.metabuilders.com/Tools/MasterPages.aspx) .
Having your read your email however I don't think this is particularly what
you're after. For now the best approach might be to copy/past the user
control files...which, if you have a lot of projects will become at
nightmare to maintain. Hopefully by then you'll have mastered server
controls.

Karl
 
K

Kevin Spencer

Custom Server Controls migrate from one site to another without problems, as
they are simply DLLs.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Neither a follower nor a lender be.
 
E

Eliyahu Goldin

Yeah, may be, once you have them and they do what you want them to. I second
Karl, they are too
complicated except for in the most simple cases. I started with them and
ended up with copy/paste. Wasted time. May be if I've tried anoher time I'd
have had more luck, but I don't think it worth trying if 2.0 is around the
corner.

Eliyahu
 
K

Kevin Spencer

Yeah, may be, once you have them and they do what you want them to. I

The same might be (and has been) said of classes and OOP in general. Yes,
you spend more time up front. But much less in the long run. A well-designed
server control can be re-used and re-purposed many times over.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Neither a follower nor a lender be.
 
E

Eliyahu Goldin

The same might be (and has been) said of classes and OOP in general. Yes,
you spend more time up front. But much less in the long run. A well-designed
server control can be re-used and re-purposed many times over.

OOP is well documented. Server controls are not. In fact, I recall that time
as months of continuous guessing. And they are good for limited well-defined
functions, not as a template for building new pages.

Eliyahu
 
K

Kevin Spencer

OOP is well documented. Server controls are not.

???

Listen, I don't need Master Pages, templates or what-have you. The way our
ASP.Net apps work, we build Server Controls that have generic HTML in them,
with an outer Div or Table as part of the Control. We position and style
them via CSS. The layout HTML code is lean and clean. No attributes, layout
tables, or inline styles. Can't get much simpler than that. Easy to
maintain, easy to upgrade, easy to re-use. I should know. I maintain them. I
upgrade them. I re-use them. I re-use them out the wazoo.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Neither a follower nor a lender be.
 

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

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,539
Members
45,024
Latest member
ARDU_PROgrammER

Latest Threads

Top