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

The Archive Base Latest Questions

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

I have an ASP.NET web form. This web form has an event handler that

  • 0

I have an ASP.NET web form. This web form has an event handler that generates some HTML. This HTML is based on the time-of-day, that is why it is created in the event handler. Based on the time of day, an image is created programmatically via the following method:

private Bitmap GetImageForTime(DateTime time)
{
  Bitmap bitmap = new Bitmap();

  // Dynamically build the bitmap...

  return bitmap;
}

I want to call this method when the HTML is being generated. However, I do NOT want to write the image on the server. Instead, I would like to figure out a way to write it out along with the HTML. In a sense, I’m trying to accomplish the following:

protected void myLiteral_Load(object sender, EventArgs e)
{
  string html = "<table><tr><td>";
  html += GetImageForTime(DateTime.Now);  // This is the problem because it's binary.
  html += "</td><td>";
  html += GetWeatherHtmlText();
  html += "</td></tr></table>";
  myLiteral.Text = html;
}

Is this possible? If so, how?

  • 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-15T10:30:00+00:00Added an answer on May 15, 2026 at 10:30 am

    Create another aspx page called TimeImage.aspx then in the Page_Load of the code-behind for the page put this code:

    void Page_Load(object sender, EventArgs args) {
        string mime = "image/jpeg";
        Response.ContentType = mime;
    
        Bitmap b = GetImageForTime(DateTime.Now);
    
        var codec = ImageCodecInfo.GetImageEncoders().Where(i => i.MimeType == mime).SingleOrDefault();
    
        if(codec != null)
            b.Save(Response.OutputStream, codec, null);
    }
    

    Then make your html generation look like this:

    protected void myLiteral_Load(object sender, EventArgs e)
    {
      string html = "<table><tr><td>";
      html += "<img src='TimeImage.aspx'>"
      html += "</td><td>";
      html += GetWeatherHtmlText();
      html += "</td></tr></table>";
      myLiteral.Text = html;
    }
    

    This will create an img tag that calls the TimeImage.aspx page, that page changes the response mime-type to image/jpeg, converts your bitmap to a JPG, and then saves it to the response output stream so that the image tag can display it as a JPG.

    If you prefer a different format just change the mime type at the top (e.g. “image/gif” for GIF, or “image/png” for PNG).

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

Sidebar

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.