你好,我有一个学校任务要制作一款名为“The Hang Men”的游戏,我开始制作这款游戏,但有一个大问题我无法解决
每次我点击按钮。所有元素都从页面中消失。我知道原因,因为回发。
但是如果我从按钮禁用回发,则不会发生任何事情。
有什么想法我该怎么做?如何在不创建回发的情况下单击按钮并执行某些事件?
这是代码..
abc ltr;
Words word = null;
static Label [] lbl = null;
static Button[] btn = null;
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
SetBord();
SetWords();
}
}
private void SetWords()
{
word = new Words();
Random ids = new Random();
string temp_word;
int id = ids.Next(0, word.GetListSize());
temp_word = word.GetWords(id);
lbl = new Label[word.GetWordLenght(id)];
for (int i = 0; i < word.GetWordLenght(id); i++)
{
lbl[i] = new Label();
lbl[i].ID ="lbl"+i;
lbl[i].CssClass = "LetterStyle";
lbl[i].Text = Convert.ToString(word.get_chars(id,i));
this.Words_Panel.Controls.Add(lbl[i]);
}
}
private void SetBord()
{
ltr = new abc();
btn = new Button[27];
for (int i = 0; i<27; i++)
{
btn[i] = new Button();
btn[i].ID = "btn" + i;
btn[i].Attributes.Add("runat", "server");
btn[i].Click += new EventHandler(LetterClicked);
btn[i].Width = new Unit("100px");
btn[i].Height = new Unit("49px");
btn[i].Text = "" + ltr.getLetters(i);
this.Letters.Controls.Add(btn[i]);
}
}
protected void LetterClicked(object sender, EventArgs e)
{
Button letter = (Button)sender;
letter.Enabled = false;
lbl[0].Text = letter.Text;
}