wsmith5204
asked on
Change the src of an IFrame dynamically
I'm trying to change the src of an IFrame dynamically every 30 seconds using C# code behind and a timer. Here's my web page:
<%@ Page language="c#" Codebehind="WebForm1.aspx. cs" AutoEventWireup="true" Inherits="WebApplication1. WebForm1" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScri pt" content="JavaScript">
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body MS_POSITIONING="GridLayout " bgcolor="#ffffff">
<form id="Form1" runat="server">
<iframe runat=server id='myFrame' align='right' src='about:blank' height='100%' width='75%'></iframe>
</form>
</body>
</HTML>
Here's my code behind without the "using" includes:
namespace WebApplication1
{
public class WebForm1 : System.Web.UI.Page
{
protected System.Web.UI.HtmlControls .HtmlGener icControl myFrame;
private System.Timers.Timer timer1;
private int state;
private double startTime;
private void Page_Load(object sender, System.EventArgs e)
{
theState = 1;
startTime = getTime();
}
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.P age_Load);
this.components = new System.ComponentModel.Cont ainer();
this.timer1 = new System.Timers.Timer();
//
// timer1
//
this.timer1.Enabled = true;
this.timer1.Interval = 1000;
this.timer1.Elapsed += new ElapsedEventHandler(this.m yTest);
}
private void myTest(object sender, ElapsedEventArgs e)
{
double now = getTime();
if(theState == 1 && (now > startTime + 30))
{
theState = 2;
startTime = getTime();
myFrame.Attributes["src"] = "http://dc.indymedia.org/";
}
else if(theState == 2 && (now > startTime + 30))
{
theState = 3;
startTime = getTime();
myFrame.Attributes["src"] = "http://www.zmag.org/ZNETTOPnoanimation.html";
}
else if(theState == 3 && (now > startTime +30))
{
theState = 4;
startTime = getTime();
myFrame.Attributes["src"] = "http://www.alternet.org";
}
else if(theState == 4 && (now > startTime + 30))
{
theState = 5;
startTime = getTime();
myFrame.Attributes["src"] = "http://www.thenation.com/";
}
else if(theState == 5 && (now > startTime + 30))
{
theState = 6;
}
}
private double getTime()
{
DateTime d1 = DateTime.Now;
return((double)d1.Hour * 3600 + (double)d1.Minute * 60 + (double)d1.Second + (double)d1.Millisecond/100 0);
}
}
}
Iframe never changes from the initial setting. Am I missing something?
<%@ Page language="c#" Codebehind="WebForm1.aspx.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScri
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body MS_POSITIONING="GridLayout
<form id="Form1" runat="server">
<iframe runat=server id='myFrame' align='right' src='about:blank' height='100%' width='75%'></iframe>
</form>
</body>
</HTML>
Here's my code behind without the "using" includes:
namespace WebApplication1
{
public class WebForm1 : System.Web.UI.Page
{
protected System.Web.UI.HtmlControls
private System.Timers.Timer timer1;
private int state;
private double startTime;
private void Page_Load(object sender, System.EventArgs e)
{
theState = 1;
startTime = getTime();
}
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.P
this.components = new System.ComponentModel.Cont
this.timer1 = new System.Timers.Timer();
//
// timer1
//
this.timer1.Enabled = true;
this.timer1.Interval = 1000;
this.timer1.Elapsed += new ElapsedEventHandler(this.m
}
private void myTest(object sender, ElapsedEventArgs e)
{
double now = getTime();
if(theState == 1 && (now > startTime + 30))
{
theState = 2;
startTime = getTime();
myFrame.Attributes["src"] = "http://dc.indymedia.org/";
}
else if(theState == 2 && (now > startTime + 30))
{
theState = 3;
startTime = getTime();
myFrame.Attributes["src"] = "http://www.zmag.org/ZNETTOPnoanimation.html";
}
else if(theState == 3 && (now > startTime +30))
{
theState = 4;
startTime = getTime();
myFrame.Attributes["src"] = "http://www.alternet.org";
}
else if(theState == 4 && (now > startTime + 30))
{
theState = 5;
startTime = getTime();
myFrame.Attributes["src"] = "http://www.thenation.com/";
}
else if(theState == 5 && (now > startTime + 30))
{
theState = 6;
}
}
private double getTime()
{
DateTime d1 = DateTime.Now;
return((double)d1.Hour * 3600 + (double)d1.Minute * 60 + (double)d1.Second + (double)d1.Millisecond/100
}
}
}
Iframe never changes from the initial setting. Am I missing something?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER