473,225 Members | 74 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,225 software developers and data experts.

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 1464
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: BH | last post by:
I'm looking at the source code of the ASP.NET forum sample application. It has the "code-behind" classes compiled into a separate DLL, totally separated from the aspx/ascx files. Adding the class...
2
by: James Zhuo | last post by:
Hi all I've been getting the following compilation error. I should explain the background of the project that i am taking over. This is a project that has been developed by someone else a...
3
by: Kris van der Mast | last post by:
Hi, I've created a little site for my sports club. In the root folder there are pages that are viewable by every anonymous user but at a certain subfolder my administration pages should be...
2
by: paul meaney | last post by:
All, myself and another developer have been staring blankly at a screen for the past 48 hours and are wondering just what stunningly obvious thing we are missing. We are trying to load up 2...
25
by: n3crius | last post by:
hi, i just got a web host with asp.net , seemed really cool. aspx with the c# or vb IN the actual main page run fine, but when i use codebehind and make another source file ( a .cs) to go with...
7
by: J Smithers | last post by:
I have several ASPX pages (with code-behind logic) that I reuse amongst many Web sites on the same production server. Currently each Web site has its own copy of these aspx pages. I was thinking...
6
by: Paolo Pignatelli | last post by:
I have an aspx code behind page that goes something like this in the HTML view: <asp:HyperLink id=HyperLink1 runat="server" NavigateUrl='<%#"mailto:" &amp;...
29
by: John Rivers | last post by:
Hello, What good reason there is for not allowing methods in ASPX pages I can't imagine, but here is how to get around that limitation: (START) <body MS_POSITIONING="FlowLayout"> <form...
10
by: ptass | last post by:
Hi In asp.net 2.0 an aspx files .cs file is a partial class and all works fine, however, I thought I’d be able to create another class file, call it a partial class and have that compile and...
1
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
0
by: veera ravala | last post by:
ServiceNow is a powerful cloud-based platform that offers a wide range of services to help organizations manage their workflows, operations, and IT services more efficiently. At its core, ServiceNow...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: mar23 | last post by:
Here's the situation. I have a form called frmDiceInventory with subform called subfrmDice. The subform's control source is linked to a query called qryDiceInventory. I've been trying to pick up the...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.