So i need to write simple “Minesweeper” game in asp.net (Only for learning purposes – it should be almost only javascript but anyway…)
I’m creating the game board dynamically at PageLoad, by creating a Table when each TableCell contains an ImageButton.
When i create each button, i’m adding to it’s Click event my own event handler:
cellButton.Click += new EventHandler(tryOpenCell);
When i’m running the project, the game page loading exactly as expected, but when i click on any cell (which is an ImageButton as i said) the request goes back to the server code, but the button’s Event Handler never invoked. Instead, the whole process just repeat itself, means regenerating the whole table game.
So my question is why my event handler never invoked?
On Postback your button should be recreated and then it will handle the event..
Your button should be recreated in the page load event, before it can handle the event handler.