I'm still very new to asp. I'm trying to create a page that has a few buttons on it. The first is a start/stop button. When you click it it starts a stopwatch timer. When you click it again, the timer is stopped. Ideally a label displays the clock while it is running. I'm coming from a CS world, and I have the changing start to stop, however, when I'm clicking the button the page "refreshes" and I lose the timer data. My guess is something to do with view state, but not really sure. Any help qould be greatly appreciated.
Page Code
Page Code
Code:
<%@ Page Language="C#" MasterPageFile="Login.master" AutoEventWireup="true" CodeFile="roping_page.aspx.cs" Inherits="roping_page" Title="NCS Roping" %>
<asp:Content ID="Content1" ContentPlaceHolderID="MainBody" Runat="Server">
<div style="text-align: center">
NCS Roping Event<br />
<asp:SiteMapPath ID="SiteMapPath1" runat="server" Font-Names="Verdana" Font-Size="0.8em"
ParentLevelsDisplayed="1" PathSeparator=" : ">
<PathSeparatorStyle Font-Bold="True" ForeColor="#5D7B9D" />
<CurrentNodeStyle ForeColor="#333333" />
<NodeStyle Font-Bold="True" ForeColor="#7C6F57" />
<RootNodeStyle Font-Bold="True" ForeColor="#5D7B9D" />
</asp:SiteMapPath>
<br />
<asp:Menu ID="Menu1" runat="server" BackColor="#FFFBD6" DataSourceID="SiteMapDataSource1"
DynamicHorizontalOffset="2" Font-Names="Verdana" Font-Size="0.8em" ForeColor="#990000"
StaticSubMenuIndent="10px">
<StaticMenuItemStyle HorizontalPadding="5px" VerticalPadding="2px" />
<DynamicHoverStyle BackColor="#990000" ForeColor="White" />
<DynamicMenuStyle BackColor="#FFFBD6" />
<StaticSelectedStyle BackColor="#FFCC66" />
<DynamicSelectedStyle BackColor="#FFCC66" />
<DynamicMenuItemStyle HorizontalPadding="5px" VerticalPadding="2px" />
<Items>
<asp:MenuItem Text="Roping Mgmt" Value="Roping Mgmt">
<asp:MenuItem Text="New Roping" Value="New Roping"></asp:MenuItem>
<asp:MenuItem Text="Match Mgmt" Value="Match Mgmt"></asp:MenuItem>
<asp:MenuItem Text="Progressive Settings" Value="Progressive Settings"></asp:MenuItem>
</asp:MenuItem>
<asp:MenuItem Text="Roping DB Admin" Value="Roping DB Admin">
<asp:MenuItem Text="Clean Up DB" Value="Clean Up DB"></asp:MenuItem>
</asp:MenuItem>
<asp:MenuItem Text="Roping Payout" Value="Roping Payout">
<asp:MenuItem Text="Calculate Payout" Value="Calculate Payout"></asp:MenuItem>
</asp:MenuItem>
<asp:MenuItem Text="Roper Mgmt" Value="Roper Mgmt">
<asp:MenuItem Text="Add/Edit Roper" Value="Add/Edit Roper"></asp:MenuItem>
</asp:MenuItem>
</Items>
<StaticHoverStyle BackColor="#990000" ForeColor="White" />
</asp:Menu>
<asp:SiteMapDataSource ID="SiteMapDataSource1" runat="server" ShowStartingNode="False" />
<br />
<asp:GridView ID="GridView" runat="server">
</asp:GridView>
<br />
<br />
[b] <asp:Label ID="Clock" runat="server" Text="00:00:00"></asp:Label>
<br />
<asp:Button ID="btnClock" runat="server" OnClick="Start_Click" Text="Start" /><br />
<asp:Button ID="OneLeg" runat="server" Text="OneLeg" OnClick="OneLeg_Click" UseSubmitBehavior="False" /><br />
<asp:Button ID="NoShow" runat="server" Text="NoShow" UseSubmitBehavior="False" /><br />
<br />
<asp:Button ID="Post" runat="server" Text="Post" OnClick="Post_Click" /><br />
<br />[/b]
</div>
</asp:Content>
C# Code
{
Stopwatch SwClock = new Stopwatch();
protected void Start_Click(object sender, EventArgs e)
{
if (btnClock.Text == "Start")
{
SwClock.Reset();
SwClock.Start();
btnClock.Text = "Stop";
}
else
{
SwClock.Stop();
btnClock.Text = "Start";
}
string time = SwClock.Elapsed.ToString();
Clock.Text = time;
}