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 enter data that's not valid they would get an error message:
<p class="errormsg" id="percenthigh">Please enter a percent below 100</p>
<p class="errormsg" id="percentnegative">Percent cannot be below 0</p>
<p class="errormsg" id="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? And I'm interested in doing this only via C#/ASP.NET as some people have JavaScript disabled. This means that I would have to check errors on both client side and server side.