Sign In| Join
Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post May 04, 2012 02:01 PM by bbcompent1
Contributor
2501 Points
2107 Posts
May 03, 2012 01:58 PM|LINK
Hi,
I have 2 divs on my web page and I would like to show one of them at a time (lest say for 1 minute). How can I do it on code behind?
Best Regards.
All-Star
32974 Points
8500 Posts
Moderator
May 03, 2012 02:04 PM|LINK
You can make use of two timer controls. Place a timer on the page, then in code behind, change visibility of each one. The code behind would probably look something like this (place them inside panels):
ASPX Page: <asp:Timer ID="Timer1" runat="server" Interval="60000" ontick="Timer1_Tick"> </asp:Timer> <asp:Timer ID="Timer2" runat="server" Interval="120000" ontick="Timer1_Tick"> </asp:Timer>
Code behind: protected void Timer1_Tick(object sender, EventArgs e) { Panel1.Visible = true; Panel2.Visible = false; Timer1.Enabled = false;
} protected void Timer2_Tick(object sender, EventArgs e) { Panel1.Visible = false; Panel2.Visible = true; Timer2.Enabled = false; }
May 03, 2012 05:49 PM|LINK
Hi bbcompent1,
Thanks for your reply. There is an update panel on my page and I wonder does the timer effect the update panel or the opposite?
Edit1: Can I trigger this update panel with the timer?
May 04, 2012 11:51 AM|LINK
Also I want it to work for every 1 minute
May 04, 2012 12:43 PM|LINK
By the way I modified your code as follows:
Protected Sub Timer1_Tick(sender As Object, e As EventArgs) If panel2.Attributes("class").Contains("hide") Then takimadi11.InnerHtml = "Real Madrid" + "<br>" + "5" takimadi21.InnerHtml = "Barcelona" + "<br>" + "0" Label2.Text = "555" panel2.Attributes("class") = "display" panel1.Attributes("class") = "hide" Else takimadi1.InnerHtml = "Fenerbahçe" + "<br>" + "2" takimadi2.InnerHtml = "Galatasaray" + "<br>" + "0" panel1.Attributes("class") = "display" panel2.Attributes("class") = "hide" End If BindGrid() End Sub
At first panel2 has hide class.
Best regards.
May 04, 2012 02:01 PM|LINK
Very clever indeed! I'm impressed and I'm keeping this one around as a techtip next time I need to do that with panels and basing it on classes.
cenk1536
Contributor
2501 Points
2107 Posts
Show/Hide Div at a time interval?
May 03, 2012 01:58 PM|LINK
Hi,
I have 2 divs on my web page and I would like to show one of them at a time (lest say for 1 minute). How can I do it on code behind?
Best Regards.
bbcompent1
All-Star
32974 Points
8500 Posts
Moderator
Re: Show/Hide Div at a time interval?
May 03, 2012 02:04 PM|LINK
You can make use of two timer controls. Place a timer on the page, then in code behind, change visibility of each one. The code behind would probably look something like this (place them inside panels):
ASPX Page: <asp:Timer ID="Timer1" runat="server" Interval="60000" ontick="Timer1_Tick"> </asp:Timer> <asp:Timer ID="Timer2" runat="server" Interval="120000" ontick="Timer1_Tick"> </asp:Timer>Code behind: protected void Timer1_Tick(object sender, EventArgs e) { Panel1.Visible = true; Panel2.Visible = false;Timer1.Enabled = false;
} protected void Timer2_Tick(object sender, EventArgs e) { Panel1.Visible = false; Panel2.Visible = true;Timer2.Enabled = false; }
cenk1536
Contributor
2501 Points
2107 Posts
Re: Show/Hide Div at a time interval?
May 03, 2012 05:49 PM|LINK
Hi bbcompent1,
Thanks for your reply. There is an update panel on my page and I wonder does the timer effect the update panel or the opposite?
Best Regards.
Edit1: Can I trigger this update panel with the timer?
cenk1536
Contributor
2501 Points
2107 Posts
Re: Show/Hide Div at a time interval?
May 04, 2012 11:51 AM|LINK
Also I want it to work for every 1 minute
cenk1536
Contributor
2501 Points
2107 Posts
Re: Show/Hide Div at a time interval?
May 04, 2012 12:43 PM|LINK
By the way I modified your code as follows:
Protected Sub Timer1_Tick(sender As Object, e As EventArgs) If panel2.Attributes("class").Contains("hide") Then takimadi11.InnerHtml = "Real Madrid" + "<br>" + "5" takimadi21.InnerHtml = "Barcelona" + "<br>" + "0" Label2.Text = "555" panel2.Attributes("class") = "display" panel1.Attributes("class") = "hide" Else takimadi1.InnerHtml = "Fenerbahçe" + "<br>" + "2" takimadi2.InnerHtml = "Galatasaray" + "<br>" + "0" panel1.Attributes("class") = "display" panel2.Attributes("class") = "hide" End If BindGrid() End SubAt first panel2 has hide class.
Best regards.
bbcompent1
All-Star
32974 Points
8500 Posts
Moderator
Re: Show/Hide Div at a time interval?
May 04, 2012 02:01 PM|LINK
Very clever indeed! I'm impressed and I'm keeping this one around as a techtip next time I need to do that with panels and basing it on classes.