Creating buttons on the fly - asp.net - postback not working
Can someone tell me why when i run the following code - it creates a button - and when i click on it - instead of creating a new button based on logic - it clears the screen.
Code:
<script runat="server">
Protected WithEvents frmButton As System.Web.UI.WebControls.Button
Private Sub Page_sub(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
if not ispostback then
setupButtons(44)
end if
end sub
private sub setupButtons(byval dbl as double)
frmButton = New Button()
frmButton.ID = "btnSkip" & dbl
AddHandler frmButton.Click, AddressOf SkipSection
frmButton.Text = "button " & dbl
Form1.Controls.Add(frmButton)
Form1.controls.add(New LiteralControl("
"))
end sub
Sub SkipSection(ByVal sender As System.Object, ByVal e As System.EventArgs)
setupButtons(34)
end sub
</script>
<form runat="server" id="form1">
</form>
Last edited by digioz; 10-07-06 at 10:39 PM.
Reason: Please use CODE tags
The thumb rule is that never code any ui things in Page.Init event, use Page.Load event instead. Page.Init is best used for initialising class members only.
regards,
Naresh.