DataList And Posting back to other page
Hi,
I have a datalist that stored a button once the button clicked the user is moved to another page, right now i have two problems, from some reason when i press the button the original page DataList2_ItemCreated
is been fired and that's creating errors since the datalist items can not be found, i've overcome that by placing try catch block where i use these items.
the second problem i have is that i can't find the button control in the second page, this is the code i use in the second page:
Code:
If PreviousPage.IsPostBack Then
Dim imgBtn As ImageButton = CType(PreviousPage.FindControl("btnAddToCart"), ImageButton)
If Not imgBtn Is Nothing Then
Response.Write("found")
Else
Response.Write("Not Found")
End If
End If
Thanks!
Re: DataList And Posting back to other page
a.) How are you navigating to the 2nd page? Is it a cross page postback? If not PreviousPage property will not work. If yes, do you see the expected value in Page.PreviousPage?
b.) DataList2_ItemCreated: There is a great likelihood that you are doing the data bind of data list irrespective of whether it's a page postback or not. If you don't expect this to be fired, then just consuming the exception and moving ahead is not the right option to go ahead with.
Re: DataList And Posting back to other page
I already understood why i can't find the control, and i have the solution, but i still don't understand why when i press on one of the imagebuttons that are part of the DataList
and that have PostBackUrl property, before the page move from page1 to page2, the DataList2_ItemCreated that belongs to Page1 is been fired...
Re: DataList And Posting back to other page
On Page1, at what all places are you binding the DataList to a datasource? Is any of that code point hit during the postback?
Re: DataList And Posting back to other page
Hey,
Can you show your code from your other page?
Also, I really would encourage you to use the debugging functionality that you get within Visual Studio, rather then trying to debug the application using Response.Write's. This just confuses the matter. Either set breakpoints in your code, or use Debug.Write or Trace.Write and watch the output window. There are so many other options you can use instead of doing Response.Write.
Gary