Note that there are some explanatory texts on larger screens.

plurals
  1. PObest practices for dynamic content
    primarykey
    data
    text
    <p>I have a pretty extensive Classic ASP background (using server-side javascript), and my company is finally (FINALLY) making the push towards recoding everything in ASP.Net (using C#). I have a good grasp on good programming practices in Classic ASP and I usually try to make sure I code things the "right" way. I've been reading ASP.Net tutorials and feel like I have a pretty understanding of the basics. I have good discipline about separating client side javascript into external js files, keeping styling outside of the markup in external css files, etc. So, when reading these novice tutorials I understand the concept of the code-behind pages. It makes sense to me to separate the c# code from what will ultimately become the markup for the page. Making &lt; asp:button > objects and the code-behind rules to alter them makes perfect sense.</p> <p>However, I'm having a hard time wrapping my head around how to do something simple like I would have done in Classic ASP like this:</p> <pre><code>&lt;% if (condition) { %&gt; &lt;input type="button" value="click me" onclick="dosomething()" /&gt; &lt;% } else { %&gt; &lt;span&gt;You don't have permission to see the button&lt;/span&gt; &lt;% } %&gt; </code></pre> <p>I'm having a hard time trying to figure out how I'm supposed to fit the conditional stuff you see above into the code-behind page. If I was showing a button under both circumstances, I'd make an <code>&lt;asp:button&gt;</code> object and style it in the code-behind page accordingly - but in the example above I'm only showing the button if the condition is true, and a span block if false.</p> <p>I know that you don't HAVE to put ALL the c# code in the code-behind page. I can use the <code>&lt;% %&gt;</code> tags the same way I would do in Classic ASP. But, if I do that then it seems to me that it lessens the relevance of the code-behind page. For example, I know you can use an external css stylesheet to stylize your page and at the same time use inline styles on individual tags as well. I believe this to be poor practice, however. It makes it difficult to later have to adjust the styles on that element if you don't know whether to look in the markup or in the css file to find the relevant styles affecting that element. </p> <p>It seems to me that the same would hold true for your markup and code-behind pages. Is it just a necessary evil to have to mix the 2, or is there a better way to do what I'm demonstrating above?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload