Separating Content (aspx) from Code (aspx.cs) in ASP.NET
- by firedrawndagger
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?