Click here to Skip to main content
15,883,749 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am trying to get what is a fairly simple to create in asp.net and run on a windows azure server to work on a linux server. Everything I have tried chases me down a rabbit whole of MVC, DOTVVM and the like. All I know about javascript is 'Google it, and someone somewhere probably did, so copy and paste.

This is the desired result in action.

http://www.blanchardtech.com/webform1

The code for the aspx is below

What I have tried:

ASPX
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="Blanchardtech.WebForm1" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
        <title>Weather</title>
    <script>
        window.setInterval('refresh()', 60000);
        function refresh() {
            window.location.reload();
        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
        <div>
            <asp:Literal ID="OT" runat="server" />
        </div>
    </form>
</body>
</html>



CS

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Blanchardtech
{
    public partial class WebForm1 : System.Web.UI.Page
    {
        string filetime = string.Empty;
        string outsidetemp = string.Empty;
        string insidetemp = string.Empty;   
        string outsidehumidity = string.Empty;  

        protected void Page_Load(object sender, EventArgs e)
        {
            filetime =  System.DateTime.Now.ToString("mm");
            outsidetemp = "https://cws.a2hosted.com/weather/OutsideTemp.gif?" + filetime;
            insidetemp = "https://cws.a2hosted.com/weather/InsideTemp.gif?" + filetime;
            outsidehumidity = "https://cws.a2hosted.com/weather/OutsideHumidity.gif?" + filetime;
            OT.Text += "<img src=" + outsidetemp + "><img src=" + insidetemp + "><img src=" + outsidehumidity + ">";
        }
    }
}
Posted
Updated 19-May-22 12:47pm
v3

You don't need any server-side code for that.
HTML
<!doctype html>
<html>
<head>
    <title>Weather</title>
</head>
<body>
    <div>
        <img id="outsideTemp">
        <img id="insideTemp">
        <img id="outsideHumidity">
    </div>
    <script>
    const updateData = () => {
        const minutes = new Date().getMinutes();
        const m = minutes < 10 ? `0${minutes}` : minutes.toString();
        document.getElementById("outsideTemp").src = `https://cws.a2hosted.com/weather/OutsideTemp.gif?${m}`;
        document.getElementById("insideTemp").src = `https://cws.a2hosted.com/weather/InsideTemp.gif?${m}`;
        document.getElementById("outsideHumidity").src = `https://cws.a2hosted.com/weather/OutsideHumidity.gif?${m}`;
    };
    
    setInterval(updateData, 60000);
    updateData();
    </script>
</body>
</html>
Demo[^]
 
Share this answer
 
Awesome, worked like a charm. Thank you so very much. I spent 3 days running down rabbit holes looking for something so simple, I feel silly
 
Share this answer
 
Ok, bad news, the reason the server side push is need is that if the computer sleep mode for the screen, firefox, chrome and edge all stop updating, while with the original code, they can go to sleep and the push will keep pushing when the screen is asleep.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900