Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Runtime adding, removing items in UpdatePanel and addhandlers

Status
Not open for further replies.

Foretrenty

Programmer
Feb 25, 2007
3
US
I did not cut and paste actual code as it is too long and contains many other sensitive information. I will try to describe my problem in plain english and psuedocode as below:

I have the following codes:

Private Sub ShowItemDetails(ByVal ItemName)

(Clear page's main updatepanel)

(Create new button "See other products in category")
(AddHandler to button for button.click event to AddressOf Event_ShowProductCategory)

(Draw the updatepanel on client's browser using "UpdatePanel.Update")

End Sub

Private Sub ShowItemCategory(ByVal CategoryName)

(Clear page's main updatepanel)

(Create new imagebutton for each product in the category. They look like thumbnails on the actual page)
(AddHandler to imagebutton for imagebutton.click event to AddressOf Event_ShowProductDetails)

(Create one new button after all the thumbnails is added. The text for the button is "See other categories...")
(AddHandler to button for button.click event to AddressOf Event_ShowProductSummary)

(Draw the updatepanel on client's browser using "UpdatePanel.Update")

End Sub

Private Sub ShowItemSummary()

(Clear page's main updatepanel)

(Create new imagebutton(s) for up to 3 products for each category. So there are up to 3 thumbnails for each category, but all categories are shown on actual page)
(AddHandler to each imagebutton(s) for imagebutton.click event to AddressOf Event_ShowProductDetails)

(Create one new button each category. The text for the button is "See category...", therefore there is one such button for one category. )
(AddHandler to button for button.click event to AddressOf Event_ShowProductCategory)

(Draw the updatepanel on client's browser using "UpdatePanel.Update")

End Sub

Protected Sub Event_ShowProductSummary(ByVal sender As Object, ByVal e As System.EventArgs)
ShowItemSummary()
End Sub

Protected Sub Event_ShowProductCategory(ByVal sender As Object, ByVal e As System.EventArgs)
Dim SourceButton As Button = sender
ShowItemCategory(SourceButton.CommandArgument)
End Sub

Protected Sub Event_ShowProductDetails(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs)
Dim SourceImage As ImageButton = sender
ShowItemDetails(SourceImage.CommandArgument)
End Sub


This is all presented on
I was thinking the problem was maybe about viewstate and dynamic controls. I read about them and I just dont understand where my error is at.

I put tried to put them codes in page load and page init, they all gave me smae result.

Only the summary page when the page first load up works correctly. When you click on "See other products in category" at the product's details page, it goes back to summary. When you click on the thumbnails where you are suppose to go to product details, it goes back to summary again.

Is there a problem where I should not addhandlers in the updatepanel and clear them and add another set of handlers? Are previous handlers cleared when I do updatepanel.ContentTemplateContainer.controls.clear ?

Even if I did not clear the handlers, it should have work. It gives me headaches.. please help.
 
There is no way we can help you with your problem if you aren't willing to paste some code
 
Well is that a right approach for using addhandlers with updatepanel?
Is there anything wrong with the logic and the way I implemented those components? Having viewstates and client - server cycle in mind?
The source is very long and would probably makes finding the problem harder. It also contains many formatting information.
 
I did not get good reponse probably because of the way I frame my question and topic.

To simulate my problem,

Add a placeholder call "PlaceHolder1" on a new website project and paste the code below.

(Dont worry, this code will not hang up your machine or do harmful things.)



Partial Class _Default
Inherits System.Web.UI.Page

Dim UP1 As New UpdatePanel

Protected Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init
UP1 = New UpdatePanel
UP1.ID = "Body"
UP1.UpdateMode = UpdatePanelUpdateMode.Conditional
Page.FindControl("PlaceHolder1").Controls.Add(UP1)

show1()
End Sub

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

End Sub

Sub show1()
Dim Body As UpdatePanel = Page.FindControl("Body")

Body.ContentTemplateContainer.Controls.Clear()

Dim label1 As New Label
label1.Text = "This is show 1 calling..."
Body.ContentTemplateContainer.Controls.Add(label1)

Dim button1 As New Button
button1.Text = "Goto Show 2"
button1.CommandArgument = "Show 2"
AddHandler button1.Click, AddressOf event_show2
Body.ContentTemplateContainer.Controls.Add(button1)

Dim button2 As New Button
button2.Text = "Goto Show 3"
button2.CommandArgument = "Show 3"
AddHandler button2.Click, AddressOf event_show3
Body.ContentTemplateContainer.Controls.Add(button2)

Body.Update()
End Sub

Sub show2()
Dim Body As UpdatePanel = Page.FindControl("Body")

Body.ContentTemplateContainer.Controls.Clear()

Dim label1 As New Label
label1.Text = "This is show 2 calling..."
Body.ContentTemplateContainer.Controls.Add(label1)

Dim button1 As New Button
button1.Text = "Goto Show 3"
button1.CommandArgument = "Show 3"
AddHandler button1.Click, AddressOf event_show3
Body.ContentTemplateContainer.Controls.Add(button1)

Dim button2 As New Button
button2.Text = "Goto Show 1"
button2.CommandArgument = "Show 1"
AddHandler button2.Click, AddressOf event_show1
Body.ContentTemplateContainer.Controls.Add(button2)

Body.Update()
End Sub

Sub show3()
Dim Body As UpdatePanel = Page.FindControl("Body")

Body.ContentTemplateContainer.Controls.Clear()

Dim label1 As New Label
label1.Text = "This is show 3 calling..."
Body.ContentTemplateContainer.Controls.Add(label1)

Dim button1 As New Button
button1.Text = "Goto Show 1"
button1.CommandArgument = "Show 1"
AddHandler button1.Click, AddressOf event_show1
Body.ContentTemplateContainer.Controls.Add(button1)

Dim button2 As New Button
button2.Text = "Goto Show 2"
button2.CommandArgument = "Show 2"
AddHandler button2.Click, AddressOf event_show2
Body.ContentTemplateContainer.Controls.Add(button2)

Body.Update()
End Sub

Protected Sub event_show1(ByVal sender As Object, ByVal e As System.EventArgs)
Dim source As Button = sender
If source.CommandArgument = "Show 1" Then
show1()
End If
End Sub

Protected Sub event_show2(ByVal sender As Object, ByVal e As System.EventArgs)
Dim source As Button = sender
If source.CommandArgument = "Show 2" Then
show2()
End If
End Sub

Protected Sub event_show3(ByVal sender As Object, ByVal e As System.EventArgs)
Dim source As Button = sender
If source.CommandArgument = "Show 3" Then
show3()
End If
End Sub

End Class


Only buttons on the first page the loads up "Show 1" works correctly. Buttons on other 'Show' pages incorrectly return to 'Show 1' when clicked.

Can anyone help me with this please? Maybe it is the way I implemented updatepanel or addhandlers?



 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top