disable postback from button in asp.net

7dodcom

New Member
Hallo i have a school task to build a game called "The Hang Men" , i started to build this game but there is one big issue that i cant Solve itevery time that i click on the button. all the elements disappear from the page. i know the reason for that, its becase of the postback.but if i disable from the button the postback , no thing happens.any ideas how can i go it? how can i click a button and do some event without creating a postback?this is the code..\[code\]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 = new Label(); lbl.ID ="lbl"+i; lbl.CssClass = "LetterStyle"; lbl.Text = Convert.ToString(word.get_chars(id,i)); this.Words_Panel.Controls.Add(lbl); }}private void SetBord(){ ltr = new abc(); btn = new Button[27]; for (int i = 0; i<27; i++) { btn = new Button(); btn.ID = "btn" + i; btn.Attributes.Add("runat", "server"); btn.Click += new EventHandler(LetterClicked); btn.Width = new Unit("100px"); btn.Height = new Unit("49px"); btn.Text = "" + ltr.getLetters(i); this.Letters.Controls.Add(btn); }}protected void LetterClicked(object sender, EventArgs e){ Button letter = (Button)sender; letter.Enabled = false; lbl[0].Text = letter.Text;} \[/code\]
 
Back
Top