Postback and databinding question

Discussion in 'ASP .Net' started by Froefel, Aug 27, 2007.

  1. Froefel

    Froefel Guest

    Probably a beginner's question:

    My page has AutoEventWireup=true.
    I have a gridview that's bound to an ObjectDataSource that returns
    projects as a DataView. One of the columns is an Imagebutton that,
    when clicked, takes the user to the details page of the requested
    project.

    Everything is working OK, except that too many events are firing
    needlessly.
    Here's the order of events when I first load the page:
    1. Page_Init
    2. Page_Load
    3. Page_PreRender
    4. ObjectDataSource's SelectMethod is called and returns a
    Dataview
    5. GridView1_RowDataBound.... (for each row in the gridview
    control because some icons need to be drawn based on each row's
    content)

    And here's the order of events when I subsequently click the link in
    one the rows:
    1. Page_Init
    2. ObjectDataSource's SelectMethod is called and returns a
    Dataview
    3. GridView1_RowDataBound
    4. Page_Load
    5. Page_PreRender
    6. GridView1_RowCommand
    [followed by the events for the new page]

    When first loading the page, things are OK. However, when clicking the
    link, it appears that too much is happening; the gridview should't be
    repopulated because I'm moving away to another page anyway.
    In the RowCommand event I packed the requested action
    ("SelectProject") in the CommandType parameter and the selected
    projectID in the CommandArgument, so I don't need access to the
    gridview data anymore in order to go to the requested page.

    How should I handle this? Any suggestions are welcome.

    -- Hans
     
    Froefel, Aug 27, 2007
    #1
    1. Advertising

  2. Hans,

    Your eventing sounds like a pretty typical page cycle. These events are
    needed and your page has to rebuild so that button once again exists to
    "receive" the event and fire away. One other approach would be to eliminate
    your postback all together. Try using a 'asp:hyperlink' with the
    'navigateurl' property set to a different page or possibly a 'asp:button' or
    'asp:imagebutton' with the 'postbackurl' properties but you will embed your
    command names and arguments into the url at the time that you build your
    original page.

    Hope this gets you going in the right direction.

    --

    Andrew Robinson
    http://blog.binaryocean.com/


    "Froefel" <> wrote in message
    news:...
    > Probably a beginner's question:
    >
    > My page has AutoEventWireup=true.
    > I have a gridview that's bound to an ObjectDataSource that returns
    > projects as a DataView. One of the columns is an Imagebutton that,
    > when clicked, takes the user to the details page of the requested
    > project.
    >
    > Everything is working OK, except that too many events are firing
    > needlessly.
    > Here's the order of events when I first load the page:
    > 1. Page_Init
    > 2. Page_Load
    > 3. Page_PreRender
    > 4. ObjectDataSource's SelectMethod is called and returns a
    > Dataview
    > 5. GridView1_RowDataBound.... (for each row in the gridview
    > control because some icons need to be drawn based on each row's
    > content)
    >
    > And here's the order of events when I subsequently click the link in
    > one the rows:
    > 1. Page_Init
    > 2. ObjectDataSource's SelectMethod is called and returns a
    > Dataview
    > 3. GridView1_RowDataBound
    > 4. Page_Load
    > 5. Page_PreRender
    > 6. GridView1_RowCommand
    > [followed by the events for the new page]
    >
    > When first loading the page, things are OK. However, when clicking the
    > link, it appears that too much is happening; the gridview should't be
    > repopulated because I'm moving away to another page anyway.
    > In the RowCommand event I packed the requested action
    > ("SelectProject") in the CommandType parameter and the selected
    > projectID in the CommandArgument, so I don't need access to the
    > gridview data anymore in order to go to the requested page.
    >
    > How should I handle this? Any suggestions are welcome.
    >
    > -- Hans
    >
     
    Andrew Robinson, Aug 30, 2007
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. John

    Postback, DataBinding, Refresh

    John, Jun 2, 2004, in forum: ASP .Net
    Replies:
    4
    Views:
    5,317
  2. Replies:
    1
    Views:
    514
    Karl Seguin [MVP]
    Oct 11, 2006
  3. jobs
    Replies:
    0
    Views:
    1,632
  4. Oleg
    Replies:
    1
    Views:
    2,846
    bruce barker
    Sep 25, 2009
  5. Earl Teigrob
    Replies:
    1
    Views:
    407
    Shravan
    Mar 1, 2004
Loading...

Share This Page