|
-
Nov 13th, 2009, 02:37 PM
#1
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!
* Rate It  If you Like it
__________________________________________________________________________________________
" Programming is like sex: one mistake and you’re providing support for a lifetime."
Get last SQL insert ID 
-
Nov 13th, 2009, 05:06 PM
#2
Fanatic Member
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.
-
Nov 13th, 2009, 05:20 PM
#3
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...
* Rate It  If you Like it
__________________________________________________________________________________________
" Programming is like sex: one mistake and you’re providing support for a lifetime."
Get last SQL insert ID 
-
Nov 13th, 2009, 05:22 PM
#4
Fanatic Member
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?
-
Nov 14th, 2009, 05:09 AM
#5
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|