<% @Control Language="C#" %>
<script language="C#"
runat="server">
void
btnDecrease_Click(Object Src, EventArgs E)
{
int CurrentValue = GetCurrentValue();
CurrentValue--;
txtValue.Text = CurrentValue.ToString();
}
void
btnIncrease_Click(Object Src, EventArgs E)
{
int CurrentValue = GetCurrentValue();
CurrentValue++;
txtValue.Text = CurrentValue.ToString();
}
int
GetCurrentValue()
{
try
{
return Convert.ToInt32(txtValue.Text);
}
catch( Exception )
{
return 0; // Return 0 if txtValue.Text is not numeric
}
}
</script>
<form runat=server>
<asp:Button id="btnDecrease" text="Decrease"
onclick="btnDecrease_Click" runat="server"/>
<asp:TextBox id="txtValue" runat="server"
value="0" />
<asp:Button id="btnIncrease" text="Increase"
onclick="btnIncrease_Click" runat="server"/>
</form>