asp.net good practices?

K

Karl Hungus

Looking for a high level description of good practices.

I want to build a little admin tool for my site -- using asp.net, c#, and an
xml file as the database. Im kind of new to asp.net and im looking for a
suggestion on how to design it so that I can read and parse the xml within
my own objects and use the data to populate info in the html.

How should I use an external .cs file with an aspx page? Is there some kind
of special interface I have to implement in my cs file? Or can I design a
class (in the cs file) and instatiate it in the aspx and call methods on it?
Should I use databinding?

Basically looking for the most modular approach with least code in the
presentation layer.

Thanks in Advance,
Karl
 
M

Martha[MSFT]

One of the strengths of ASP.NET is that you can very well separate
programmatic logic code from the presentation layer. The technique is
called code-behind. Each page you write(.aspx file) is compiled into a
"Page"-derived class. So you can have an intermediate class between the
"Page" class and the class generated from the .aspx file. You can add
fields, methods and event handlers in your code-behind class and have these
inherited by the class created from the .aspx file. This removes a lot of
code from the .aspx file.
The C# file should inherit from System.Web.UI.Page.
You will have to have something like this in your .aspx file:
<%@ Page language="c#" Codebehind="Somefile.aspx.cs"
Inherits="Namespace.ClassName" %>

You can write methods in "Somefile.aspx.cs" and access it in
"Somefile.aspx". You can also handle events in your .cs file.
The Codebehind attribute is added so that the C# source is compiled whenever
the page is compiled. Alternatively, you can remove this attribute and
compile your C# class into an assembly and place it in the /bin directory of
the application.

Hope this helps.
 
G

Guest

You want to create object(s) that handle the XML file right

Just add a class to your project, pretty much same like adding web forms... Anyway, you add a class and if the class is in the same namespace as the page(it will be by default if you add it in the same folder as the web form) or in its parent namespace you can use it normally... if the newly added class is in some other namespace or a child namespace you have to include the namespace with a using ... statemen

So just add a class, something like MyXMLObject into your project. Put all the code that reads/writes the XML file in its methods. You can then normally instantiate/use this class in your webpage class or in other words in your WebFrom1.aspx.cs or whatever...
 
K

Karl Hungus

Thanks.

One other question. Assuming I write my objects, should I be retrieving the
xml data with getters called from my aspx page? or is there a better way to
do that, like databinding?


Adrijan Josic said:
You want to create object(s) that handle the XML file right?

Just add a class to your project, pretty much same like adding web
forms... Anyway, you add a class and if the class is in the same namespace
as the page(it will be by default if you add it in the same folder as the
web form) or in its parent namespace you can use it normally... if the newly
added class is in some other namespace or a child namespace you have to
include the namespace with a using ... statement
So just add a class, something like MyXMLObject into your project. Put all
the code that reads/writes the XML file in its methods. You can then
normally instantiate/use this class in your webpage class or in other words
in your WebFrom1.aspx.cs or whatever...
 

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,764
Messages
2,569,564
Members
45,040
Latest member
papereejit

Latest Threads

Top