My problem is that I pragmatically generate few buttons and text boxes in different panels and when I click one on the buttons all that is previously generated magically disappears forever. I thought that the the ispostback in the from load is enough to fix the problem but I could not make it work. Here is the code any help is greatly appreciated.
Public Class Multiplication
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not IsPostBack Then
Instruction_Panel.Visible = True
Solution_For_Panel.Visible = False
Solution_Math_Panel.Visible = False
Solution_Text_Panel.Visible = False
Navigation_Panel.Visible = False
Else
Instruction_Panel.Visible = False
Solution_For_Panel.Visible = True
Solution_Math_Panel.Visible = True
Solution_Text_Panel.Visible = True
Navigation_Panel.Visible = True
End If
End Sub
Dim First_N As Integer
Dim Second_N As Integer
Dim Your_A As Integer
Dim First_N_Arr() As String
Dim Second_N_Arr() As String
Protected Sub Check_Answer_BT_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Check_Answer_BT.Click
If Int(First_Number_TB.Text) > Int(Second_Number_TB.Text) Then
First_N = Int(First_Number_TB.Text)
Second_N = Int(Second_Number_TB.Text)
Your_A = Int(Your_Answer_TB.Text)
Else
First_N = Int(Second_Number_TB.Text)
Second_N = Int(First_Number_TB.Text)
Your_A = Int(Your_Answer_TB.Text)
End If
If First_N * Second_N = Your_A Then
Solution_For_Panel.Visible = True
Create_Textbox("Solution For", "Your Answer Is Correct", 145)
Exit Sub
End If
Instruction_Panel.Visible = False
Solution_For_Panel.Visible = True
Solution_Math_Panel.Visible = True
Solution_Text_Panel.Visible = True
Navigation_Panel.Visible = True
Dim Arr_Lenght As Integer
Arr_Lenght = First_N.ToString.Length * 2
Dim Formating As String
For i = 1 To First_N.ToString.Length * 2
Formating = Formating + "0"
Next
'Array for first number
Array.Resize(First_N_Arr, Arr_Lenght)
Dim F_N_Temp As String
F_N_Temp = First_N.ToString(Formating)
For i = 0 To F_N_Temp.Length - 1
First_N_Arr(i) = F_N_Temp.Substring(i, 1)
Next
'Array for second number
Array.Resize(Second_N_Arr, Arr_Lenght)
Dim S_N_Temp As String
S_N_Temp = Second_N.ToString(Formating)
For i = 0 To F_N_Temp.Length - 1
Second_N_Arr(i) = S_N_Temp.Substring(i, 1)
Next
'Solution For part
Create_Textbox("Solution For", "Long multiplication - Solution for " & First_N & " x " & Second_N, 250)
'Solution Math Part
Solution_Math_Panel.Controls.Add(New LiteralControl("<br>"))
For i = 0 To Arr_Lenght - 1
Create_Textbox("Solution Math", First_N_Arr(i), 15)
Next
Solution_Math_Panel.Controls.Add(New LiteralControl("<br>"))
For i = 0 To Arr_Lenght - 1
Create_Textbox("Solution Math", Second_N_Arr(i), 15)
Next
Solution_Math_Panel.Controls.Add(New LiteralControl("<hr width=60%>"))
'Solution Text Part
Solution_Text_Panel.Controls.Add(New LiteralControl("<br>"))
Solution_Text_Panel.Controls.Add(New LiteralControl("To multiply " & First_N & " by " & Second_N & ", set them up as shown by arranging the two numbers in columns."))
Create_BT("New Multiplication", 150, 30)
Create_BT("Next Step", 100, 30)
End Sub
Protected Sub Clear_BT_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Clear_BT.Click
With First_Number_TB
.Text = ""
.Focus()
End With
Second_Number_TB.Text = ""
Your_Answer_TB.Text = ""
End Sub
Dim TextBox_Arr As New ArrayList
Function Create_Textbox(ByVal Panel_Name As String, ByVal Value As String, ByVal W As Integer)
Dim Textbox_TB As New TextBox
Textbox_TB.Width = W
Textbox_TB.Visible = True
Textbox_TB.Text = Value
Textbox_TB.BorderColor = Drawing.Color.Transparent
Textbox_TB.ForeColor = Drawing.Color.Black
If Panel_Name = "Solution For" Then
Solution_For_Panel.Controls.Add(Textbox_TB)
End If
If Panel_Name = "Solution Math" Then
Solution_Math_Panel.Controls.Add(Textbox_TB)
End If
If Panel_Name = "Solution Text" Then
Solution_Text_Panel.Controls.Add(Textbox_TB)
End If
TextBox_Arr.Add(Textbox_TB)
End Function
Dim Button_Arr As New ArrayList
Function Create_BT(ByVal BT_Text As String, ByVal W As Integer, ByVal H As Integer)
Dim New_BT As New Button()
New_BT.Height = H
New_BT.Width = W
New_BT.Text = BT_Text
New_BT.Visible = True
New_BT.ID = BT_Text
Select Case BT_Text
Case Is = "Next Step"
AddHandler New_BT.Click, AddressOf Next_Step_BT_Click
Case Is = "New Multiplication"
AddHandler New_BT.Click, AddressOf New_Multiplication_BT_Click
End Select
Navigation_Panel.Controls.Add(New_BT)
Button_Arr.Add(New_BT)
End Function
Function Next_Step_BT_Click()
'When I hit the next step button this code does not get executed for some reason. Instead all panels are refresh and completly empty
Solution_Text_Panel.Controls.Clear()
Solution_Text_Panel.Controls.Add(New LiteralControl("Hello"))
End Function
Function New_Multiplication_BT_Click()
'Something is going to go in here later
End Function
End Class

New Topic/Question
Reply


MultiQuote



|