If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

Dynamic Buttons disappearing

I've created an apsx page that takes data from a XML file and loads a number of image buttons on screen. The buttons would be positioned at different places depending on co-ordinates retrieved from within the XML file. The buttons get created depending on which option the user selects which is permanently displayed on screen. . .

however, even though I've added a handler for the clicking of the image button (shown)

Thanks Phil - the article did help in understanding the page flow and loading, but it also alerted me to the saveviewstate and loadviewstate capabilities - I didnt know about these before!! Its still amateur night at ASP.NET!!

Anyway, had a lot of fun with the viewstates and reccreating buttons and whatnot. Even able to offer assistance to another post regarding dynamic web form controls!

Just as a follow up to what I was doing - managed to get the code running the way I need it to and have listed below. The form has four buttons (named Button1 - Button4), a panel named Panel1 and a label named Label1. Based it around the code within MSDN. . .

When you click on Button1 it creates 3 dynamic buttons, Button2 = 4 dynamic buttons, Button3 = 5 dynamic buttons. Button4 removes all dynamic buttons on the form. Clicking the dynamic button will display the button name in the label control.

Anyway, the code is pasted below (and could do with a good tidy up which I'm going to do right this minute!) - if anyone can see any flaws or a better way of doing this, please let me know. . . .

Public Class WebForm1
Inherits System.Web.UI.Page

#Region " Web Form Designer Generated Code "

'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

'NOTE: The following placeholder declaration is required by the Web Form Designer.
'Do not delete or move it.
Private designerPlaceholderDeclaration As System.Object

Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub

#End Region

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If Session("controlsdisplayed") = "TRUE" Then
RemoveControls()
Session("track") = "0"
viewstate("controlsadded") = Nothing
End If
If ViewState("controlsadded") Is Nothing Then
Session("track") = "3"
Session("controlsdisplayed") = "TRUE"
AddControls(3)
End If
If Session("controlsdisplayed") = "TRUE" Then
viewstate("controlsadded") = Nothing
End If
End Sub

Protected Overrides Sub LoadViewState(ByVal savedState As Object)
MyBase.LoadViewState(savedState)
If (ViewState("controlsadded") = True And CInt(Session("track")) > 0) Or Session("controlsdisplayed") = "TRUE" Then
AddControls(CInt(Session("track")))
End If
End Sub