当我在做一个预订系统时,我在我的网页中实现了几个按钮。我设法限制用户点击我网页中的按钮,但我的问题是用户现在甚至无法选择一个按钮,因为当他们尝试点击第一个按钮时,我的警报消息会弹出,要求他们只选择一个按钮。我如何允许用户只选择一个按钮,当他们尝试选择另一个按钮时,我的警报消息将开始使用。我怀疑这是我造成问题的原因。
这是我的 .cs 代码:
protected void Button1_Click(object sender, EventArgs e)
{
int counter = 0;
if (counter > 1)
{
Button1.Text = "Selected";
Button1.BackColor = System.Drawing.Color.DarkGreen;
Button2.Text = "Selected";
Button2.BackColor = System.Drawing.Color.DarkGreen;
startingTime.Text = "9AM";
endingTime.Text = "11AM";
}
else
{
ScriptManager.RegisterStartupScript(this, GetType(), "showalert", "alert('Please select one slot only');", true);
}
}
protected void Button2_Click(object sender, EventArgs e)
{
int counter = 1;
if (counter > 0)
{
Button2.Text = "Selected";
Button2.BackColor = System.Drawing.Color.DarkGreen;
Button3.Text = "Selected";
Button3.BackColor = System.Drawing.Color.DarkGreen;
startingTime.Text = "10AM";
endingTime.Text = "12PM";
}
else
{
ScriptManager.RegisterStartupScript(this, GetType(), "showalert", "alert('Please select one slot only');", true);
}
}
protected void Button3_Click(object sender, EventArgs e)
{
int counter = 1;
if (counter > 0)
{
Button3.Text = "Selected";
Button3.BackColor = System.Drawing.Color.DarkGreen;
startingTime.Text = "11AM";
endingTime.Text = "1PM";
}
else
{
ScriptManager.RegisterStartupScript(this, GetType(), "showalert", "alert('Please select one slot only');", true);
}
}