Separating Content (aspx) from Code (aspx.cs) in ASP.NET

Posted by firedrawndagger on Stack Overflow See other posts from Stack Overflow or by firedrawndagger
Published on 2010-05-13T19:31:56Z Indexed on 2010/05/13 19:34 UTC
Read the original article Hit count: 258

I would like to know what is the best practice on separating the content of an aspx page (ASP.NET 3.5) from the code (I'm using C#). I have a form that users can type data in - for example they are allowed to enter a percent. If they

Otherwise for example I would like to display the following error messages:

<p id="errormsg" class="percenthigh">Please enter a percent below 100</p>
<p id="errormsg" class="percentnegative">Percent cannot be below 0</p>
<p id="errormsg" class="percentnot">This is not a percent</p>

So in essence I'm hiding the error messages and showing one depending on what the user input is.

I believe this is the best way to seperate the content from the code behind. However, how do I select elements and hide/unhide them depending on the user input? I'm aware I can do a runat="server" on the elements but the problem is that I can't select by class and am limited only to ID's.

What workarounds do you recommend? Aside from putting in the values in code behind which is notoriously difficult to debug.

Also has this been "fixed" in ASP.NET 4?

© Stack Overflow or respective owner

Related posts about ASP.NET

Related posts about separation-of-concerns