5 Replies - 3971 Views - Last Post: 19 November 2012 - 06:12 PM Rate Topic: -----

#1 okwhatnow   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 04-November 12

Problem with IsPostBack on Panels

Posted 12 November 2012 - 03:59 PM

Hello Everyone,
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



Is This A Good Question/Topic? 0
  • +

Replies To: Problem with IsPostBack on Panels

#2 November-06   User is offline

  • D.I.C Regular

Reputation: 54
  • View blog
  • Posts: 488
  • Joined: 04-January 11

Re: Problem with IsPostBack on Panels

Posted 12 November 2012 - 07:34 PM

Your Next_Step_BT_Click() isn't being executed, how about the New_ Multiplication_BT_Click()? Is it being executed? If when you are debugging, you don't step into these methods, then maybe the problem lies with the way you are adding handlers.
Was This Post Helpful? 1
  • +
  • -

#3 okwhatnow   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 04-November 12

Re: Problem with IsPostBack on Panels

Posted 12 November 2012 - 09:42 PM

View PostNovember-06, on 12 November 2012 - 07:34 PM, said:

Your Next_Step_BT_Click() isn't being executed, how about the New_ Multiplication_BT_Click()? Is it being executed? If when you are debugging, you don't step into these methods, then maybe the problem lies with the way you are adding handlers.


Hum... non of the buttons gets executed... well I use very similar method for vb forms and it works. After adjusting few little things and adding it to my .net program it show no problems and it runs. However, when I put a break inside the functions non get executed. I really feel like I may need to look into using Update Panel or somthing that partially updated the form. Anyways, thanks for the thought Mr. November-06 :)/> ...still on the look-out for solution
Was This Post Helpful? 0
  • +
  • -

#4 November-06   User is offline

  • D.I.C Regular

Reputation: 54
  • View blog
  • Posts: 488
  • Joined: 04-January 11

Re: Problem with IsPostBack on Panels

Posted 19 November 2012 - 03:00 AM

View Postokwhatnow, on 12 November 2012 - 09:42 PM, said:

Hum... non of the buttons gets executed... well I use very similar method for vb forms and it works. After adjusting few little things and adding it to my .net program it show no problems and it runs. However, when I put a break inside the functions non get executed. I really feel like I may need to look into using Update Panel or somthing that partially updated the form. Anyways, thanks for the thought Mr. November-06 :)/>/> ...still on the look-out for solution


I am glad I was able to help though just a little but really I am female so that should have been Ms. instead of Mr. Anyway, it's hard to know by the name so it's okay. How's the program now? Have you found a solution?
Was This Post Helpful? 0
  • +
  • -

#5 okwhatnow   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 04-November 12

Re: Problem with IsPostBack on Panels

Posted 19 November 2012 - 04:26 PM

View PostNovember-06, on 19 November 2012 - 03:00 AM, said:

I am glad I was able to help though just a little but really I am female so that should have been Ms. instead of Mr. Anyway, it's hard to know by the name so it's okay. How's the program now? Have you found a solution?


Hey Ms. November-06 I appologies for the gender mistake. That is a sweet name by the way... now it makes sense that not many guy will choose it. Anyways, well it is a little math tuturing system that I am creating. I figured out it will be easier to learn some javascript and that is what I am up to right now. Since I am switching the problem to javascript I am not sure if I can post it here, but if no one oppose by the time I am done I will post in this thread.
Was This Post Helpful? 0
  • +
  • -

#6 November-06   User is offline

  • D.I.C Regular

Reputation: 54
  • View blog
  • Posts: 488
  • Joined: 04-January 11

Re: Problem with IsPostBack on Panels

Posted 19 November 2012 - 06:12 PM

The gender mistake doesn't really bother me so it's okay. I had a hard disk failure before, needed to reformat the whole disk, no back-ups and all my programs got lost (including the ones I created myself). I could not sleep. My body was yearning to develop and it was the whole of November 6 2009 that I did nothing but talk with Visual Studio. I was still a student back then and I really yearn to learn. I was more into Math programs back then since I majored in Mathematics and it was such a memorable day. So I used that day to name myself here.

I am not sure if you can post your javascript here but I am really interested to know on how you solve things. I still have a lot to know and hopefully I can learn a lot by talking to developers here.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1