Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 818161
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T02:06:30+00:00 2026-05-15T02:06:30+00:00

Would this code be considered bad practice: <div id=sidebar> <% =DisplayMeetings(12) %> </div> This

  • 0

Would this code be considered bad practice:

<div id="sidebar">
  <% =DisplayMeetings(12)  %>
</div>

This is a snippet of code from the default.aspx of a small web app I have worked on. It works perfectly well, runs very fast, but as always, I am aware of the fact that just because it works, doesn’t mean it is OK.

Basically, the DisplayMeetings subroutine outputs a bunch of formatted HTML (an unordered list actually), with no formatting, just the requisite html, and then my CSS performs all the necessary formatting.

The data for generating the list comes from an SQL server database (the parameter controls how many rows to return) and I am using stored procedures and datareader for fast access. This keeps my front-end extraordinary simple and clean, imho, and lets me do all the work in VB or C# in a separate module.

I could of course use a databound repeater (and probably 6 or more other methods) of accomplishing the same thing, but are they any better? Other than loosing the design-time features of VS2010?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T02:06:32+00:00Added an answer on May 15, 2026 at 2:06 am

    The only thing “wrong” with your approach is that it mixes code and display, which you typically want to avoid wherever possible. If you have to have a procedurally generated portion of HTML (because it’s just that difficult to do with controls, or whatever), create a control responsible for generating that HTML and embed it in the larger page/control that contains it.

    is the “wrong” part, that the subroutine is returning HTML, or is it that I have a code-snippet executed from within the HTML markup?

    Both, in a way. And also neither.

    There’s nothing directly “wrong” with using <%= foo %>; if there were, it wouldn’t be part of the framework. What’s “wrong” with it is that it sets up a two-way dependency that you don’t necessarily want. Your HTML markup is dependent on and has to know about the code-behind. It has to call the method, which in turn is dedicated to the markup and nothing else. If you want to make changes to your output, you may have to change the method, the markup, or both.

    What I’m trying to say is that what you’re doing makes your code less maintainable, less flexible to modify the next time you have to open the hood.

    If it’s the only way to solve a problem, then it’s the only way, and there’s nothing wrong with that. But it’s something that should be avoided, in general, if possible.

    How would I have done it? That depends on the situation, frankly. If I could have used a standard component with databinding, I’d have done that. That is always preferred. If the HTML was just too complex to use a component, I’d use a Literal control as a placeholder for the markup, and generate the markup in a separate component–likely a User Control.

    The point is that the markup knows nothing about the method used to generate the other markup, it just says “something goes here” and relies on its code-behind to handle deciding which markup to put in there.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How would I modify this code to show the animated movement (item moving from
How would I make this code smaller? Maybe a toggle, but people were saying
How would you fix this code? template <typename T> void closed_range(T begin, T end)
how would I refactor this code for ARC: - (UIGestureRecognizer *)createTapRecognizerWithSelector:(SEL)selector { return [[[UITapGestureRecognizer
Can anyone tell me why this code would not be working? $('body').on('test', function() {
would someone please write this code: this.Loaded += (s, e) => this.loaded = true;
For this code example below, usually I would use [self fall]; instead of the
I have this code that where I would normally use one line: if (tableView
I would like to sort this array but this code works if I do
Is this code correct? I'm trying to submit it and also I would like

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.