Results 1 to 5 of 5

Thread: DataList And Posting back to other page

  1. #1
    PowerPoster motil's Avatar
    Join Date
    Apr 09
    Location
    Tel Aviv, Israel
    Posts
    2,128

    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

  2. #2
    Fanatic Member
    Join Date
    Jun 04
    Location
    All useless places
    Posts
    916

    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.

  3. #3
    PowerPoster motil's Avatar
    Join Date
    Apr 09
    Location
    Tel Aviv, Israel
    Posts
    2,128

    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

  4. #4
    Fanatic Member
    Join Date
    Jun 04
    Location
    All useless places
    Posts
    916

    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?

  5. #5
    ASP.NET Moderator gep13's Avatar
    Join Date
    Nov 04
    Location
    The Granite City
    Posts
    21,744

    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
  •