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 5996253
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T00:04:37+00:00 2026-05-23T00:04:37+00:00

I’m using ASP.NET with C# 2.0. I have created some objects for a database

  • 0

I’m using ASP.NET with C# 2.0. I have created some objects for a database and each of these objects has properties which can be called natively or are called in a similar manner and create a RESTful JSON API from them.

I have a lot of tab-like things I like to call ‘modules’ on this site – the function of a module is to convert data to HTML to be displayed on the page. Idealy this needs to be done in both server side C# code for the first tab to load, then use Ajax to load the others when the tabs are clicked, however for old browsers and search engines, the tab is still a link that will load the same HTML code server side.

Currently I’ve writting the JavaScript code completely separately from the C# code that converts each module to HTML, but the method is virtually the same, just a different language. Similar to this example.

C# code

public override string GetHtml()
{
    IJsonObjectCollection<Person> response = ((Village)page).People;
    string html = "<div id=\"test\">";
    foreach (Person person in response)
    {
        html += "<div class=\"person\">";
        html += person.Name;
        if(canEdit) html += "*";
        html += "</div>";
    }
    return html + "</div>";
}

JavaScript code

function getHtml() {
    JsonRequest('/json/villages/1/people', function(response) {
        var html = '<div id="test">';
        for (int i = 0; i < response.length; i++)
        {
            var person = response[i];
            html += '<div class="person">';
            html += person.name;
            if(canEdit) html += '*';
            html += '</div>';
        }
        return html + '</div>';
    });
}

You can probably see where I’m going with this question. What would be the most efficient way of doing this? I was thinking of a few different alternatives –

1. Each ModuleToHtmlMethod could be a class that defines the method of turning this data object into HTML. I attempted this, but I stopped because I was getting too complicated.

2. Write my own scripting language that can be interpreted as C# but also ‘compiled’ into JavaScript code.

3. Just write the lot in C# and use Ajax to simply request the HTML content from C#

4. Keep the code separated and write every method twice.

I’d like to eventually allow other developers to write these ‘modules’, so maybe option 2 is the best option?

  • 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-23T00:04:37+00:00Added an answer on May 23, 2026 at 12:04 am

    I would discard option 4 as it will make maintenance more difficult and you may end up out of synch between the HTML generated via the Javascript and the one from the C# code. I would also discard the option 2 as that may make the code more difficult for other developers and also probably unnecessary.

    I would definitely generate the HTML in one place and probably expose RESTful HTML API that uses the C# existing function to return the HTML snippets. So from your Javascript you would call:

    function getHtml() {
        MyHtmlRequest('/html/villages/1/people', function(response) {
            var html = response.Text;
            return html;
        });
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have some data like this: 1 2 3 4 5 9 2 6
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
Does anyone know how can I replace this 2 symbol below from the string
I'm making a simple page using Google Maps API 3. My first. One marker
We're building an app, our first using Rails 3, and we're having to build
I have a bunch of posts stored in text files formatted in yaml/textile (from

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.