When loading the page, the labels appear first at the top. After the image appears, then the labels shift underneath the image where I want them to be.
Can the following aspx.cs and aspx simulate what you say above?
aspx.cs
using System;
namespace WebForms1
{
public partial class WebForm15 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Label1.Text = "ASP.NET MVC";
}
}
}
aspx
<%@ Page Language="C#" AutoEventWireup="true"
CodeBehind="WebForm15.aspx.cs" Inherits="WebForms1.WebForm15" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title></title>
<script type="text/javascript">
window.addEventListener('DOMContentLoaded', () => {
let img = document.querySelector('img');
setTimeout(() => {
img.src = "images/image1.jpg";
}, 1000);
});
</script>
</head>
<body>
<form id="form1" runat="server">
<asp:Image ID="Image1" runat="server" />
<br />
<asp:Label ID="Label1" runat="server"></asp:Label>
</form>
</body>
</html>
If so, remove the Label setting in the Page_Load and set the caption on the load event if the img element by JavaScript, as follows:
aspx.cs
using System;
namespace WebForms1
{
public partial class WebForm15 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
//Label1.Text = "ASP.NET MVC";
}
}
}
aspx
<%@ Page Language="C#" AutoEventWireup="true"
CodeBehind="WebForm15.aspx.cs" Inherits="WebForms1.WebForm15" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title></title>
<script type="text/javascript">
window.addEventListener('DOMContentLoaded', () => {
let img = document.querySelector('img');
setTimeout(() => {
img.src = "images/image1.jpg";
}, 1000);
img.addEventListener('load', () => {
let label = document.querySelector('span');
label.innerText = "ASP.NET MVC";
});
});
</script>
</head>
<body>
<form id="form1" runat="server">
<asp:Image ID="Image1" runat="server" />
<br />
<asp:Label ID="Label1" runat="server"></asp:Label>
</form>
</body>
</html>