Help: Keeping .ASPX pages PURE using C# Codebehind

A

Adrian

Hi All,

I am a big fan of the Codebehind model. I would like to continue to
keep my .ASPX pages FREE of any 'LOGIC' and keep it PURE 'HTML'. I
would like to know how many of you handle the following situation.
(In pseudo code to illustrate my point)

<html>
<body>
if (condition)
{
DoThis();
<asp:Label/>
...
... More HTML code
}
else
{
...Html Code...
DoThat();
DoSomethingElse();
...Html Code..
}
</body>
<html>

Of course the logic is all contained in a Codebehind file using C#. I
would like to elimate this type of design if possible and keep the
..ASPX pure from any such logic.

Does anyone have an Elegant solution to this problem? how can I keep
such conditional statements from appearing in my ASPX ?
 
M

Martin Dechev

Hi, Adrian,

For the if{}else{} parts - use containers - PlaceHolder, Panel, UserControl
etc. and play with the visibility.

For the DoThis() - DoThat() - I just can't imagine a situation that prevents
this:

Page_Load:

if(condition)
{
// adjust visibilities
DoThis();
}
else
{
// adjust visibilities
DoThat();
DoSomethingElse();
}

Hope this helps
Martin
 
K

Kevin Spencer

Hi Adrian,

You need to study object-oriented programming principles. The biggest
difference between the 2 technologies is right there. For example, look at
the code you posted. It is purely procedural. An ASP.Net Page is a class
which is a container for other classes. A class is an encapsulation of data
and functionality. So, in an ASP.Net Page, you have references in the Page
Template to classes, not code. The code encapsulated in the classes does the
functional work. And the classes render their own HTML.

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

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

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top