I am having trouble getting my delegate to work. Basically I want it to function so that when the user clicks the button the first time the label will display the driver that came in third, the second time they hit the button the label will clear and the driver that placed in second will display in its place and then finally when the click the button for the third time it will display the winner of the race
This is aspx.cs page
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace WebProgramming3.Week_3
{
public partial class Exercise1 : System.Web.UI.Page
{
static RaceResult UserClick;
//public int Clicks = 0;
protected void Page_Load(object sender, EventArgs e)
{
UserClick = new RaceResult(0);
UserClick.NbrClicksReached += User_Click_NbrClicksReached;
}
private void User_Click_NbrClicksReached(string message)
{
lblRaceResults.Text += message;
}
protected void btnRace_Click(object sender, EventArgs e)
{
UserClick.BtnClicks++;
}
}
public delegate void StringDelegate(string message);
public class RaceResult
{
public int BtnClicks { get; set; }
//Delegate
public event StringDelegate NbrClicksReached;
public RaceResult( int btnclicks)
{
BtnClicks = btnclicks;
}
public void Add(int amount)
{
if (BtnClicks == 1)
{
if (NbrClicksReached != null)
NbrClicksReached("In 3rd place is Kimi Räikkönen");
}
if (BtnClicks == 2)
{
if (NbrClicksReached != null)
NbrClicksReached("In 2nd place is Sebastian Vettel");
}
if (BtnClicks >= 3)
{
if (NbrClicksReached != null)
NbrClicksReached("In 1st place is Lewis Hamilton");
}
}
}
}
This is my aspx page
<body>
<form id="form1" runat="server">
<div>
<asp:Button ID="btnFeed" OnClick="btnRace_Click" runat="server" Text="Button" />
<asp:Label ID="lblRaceResults" runat="server" Text="Label"></asp:Label>
</div>
</form>
</body>
If my problem is unclear please feel free to ask more questions.