Postback and databinding question

F

Froefel

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
 
A

Andrew Robinson

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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top