468,119 Members | 1,901 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,119 developers. It's quick & easy.

Help: Keeping .ASPX pages PURE using C# Codebehind

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 ?


Nov 18 '05 #1
3 1356
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
"Adrian" <yingyang at c o x dot n e t> wrote in message
news:sv********************************@4ax.com...
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 ?

Nov 18 '05 #2
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.

"Adrian" <yingyang at c o x dot n e t> wrote in message
news:sv********************************@4ax.com...
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 ?

Nov 18 '05 #3
Thank You Martin and everyone for the info. sometimes things really
are that easy. :)

Thanks again!

On Tue, 24 Feb 2004 11:32:35 +0100, "Martin Dechev"
<de*******@hotmail.com> wrote:
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
"Adrian" <yingyang at c o x dot n e t> wrote in message
news:sv********************************@4ax.com.. .
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 ?


Nov 18 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by James Zhuo | last post: by
3 posts views Thread by Kris van der Mast | last post: by
2 posts views Thread by paul meaney | last post: by
25 posts views Thread by n3crius | last post: by
7 posts views Thread by J Smithers | last post: by
29 posts views Thread by John Rivers | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.