Re: asp.net good practices?

From: Martha[MSFT] (marthage_at_online.microsoft.com)
Date: 02/07/04


Date: Fri, 6 Feb 2004 21:05:19 -0800

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.

"Karl Hungus" <nnnnndddddd@hotmail.com> wrote in message
news:7ZVUb.131291$cM1.23397651@twister.nyc.rr.com...
> 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
>
>



Relevant Pages

  • Re: .ASPX -> .CS generation
    ... It does create a C# source file! ... It even showed me the command line that was used to compile it. ... No doubt, it does many things when requesting an ASPX file, but this step is ... > When you make a request to an ASPX file, it is not converted into C# file. ...
    (microsoft.public.dotnet.framework.aspnet)
  • RE: Ajax Exception Handling
    ... the aspx file displays but does not compile. ... If I use a Virtual Path Provider, I don't know a way to get the path to ... What I did in the code is to catch exception in global.asax. ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Simple datalist question
    ... and then moved your c# code from the new aspx to the code-behind? ... one thing you're missing is that when you drop a control on a form ... So by doing this, when the aspx file is loaded, the variable declaration is inherited from the code-behind class, and .NET automatically associates the loaded control in the page to it.. ...
    (microsoft.public.dotnet.framework.aspnet)
  • RE: Interpeted ASP.Net & .aspx With MS Index Server
    ... The controls for the header/footer and side menu will be compiled and be ... proper html the file will compile. ... > code outside the ASPX file like WebForm.cs etc. ... >> server via FTP. ...
    (microsoft.public.dotnet.framework.aspnet)
  • problem with connecting gridview with data in code-behind
    ... code-behind. ... The problem is that the gridview remains invisible because no records come ... code in aspx file ... Dim dtreader As SqlDataReader ...
    (microsoft.public.dotnet.framework.aspnet)

Loading