Good call on the double page_load, Tim. The "show secondary datagrid" link
there. I'd be glad to post the code-behind info, but I think you've got me
I'll definitely check out that MSDN2 link you posted on the page lifecycle.
"Tim_Mac" <tim.mackey@community.nospam> wrote in message
news:ek5z1x4yGHA.3584@TK2MSFTNGP02.phx.gbl...
> hi Steve,
> you're welcome, glad to help out.
>
> you only need to bind the topmost datagrid for the first postback. the
> reason for this is because it is a statically declared control in the
> aspx, and the viewstate is enough to maintain its state across postbacks.
> however, if you change the underlying data, i.e. run an update/delete SQL
> query, then you will need to re-bind the datagrid afterwards because the
> viewstate data will not reflect your data changes.
>
> the reason your events are getting lost for the secondary datagrid is
> because this control does not exist for any given postback unless it is
> programatically created exactly as it was previously. does that make
> sense?
>
> re: events for a DataBind()... i'm not aware of any knock-on events raised
> by calling DataBind on a control. if you set a breakpoint at the DataBind
> call, and hit F11 you will step into any user code that runs as a result
> of calling Databind.
>
> i know what you mean about the complexity of the Page lifecycle. i
> generally don't concern myself with such events, except obviously
> Page_Load. there is lots of opinion on where/when to create your dynamic
> controls. Personally i like to do it all in Page_Load because it is very
> clear then what is going on, you don't need to worry about the order of
> events. Page_Load will always run first, and then any events will fire
> after that. advanced users may say this is too simplistic, but i have done
> plenty of complex scenarios containing nested dynamic controls only using
> Page_Load.
>
> the official resource on the Page/Postback lifecycle is on MSDN2:
>
http://msdn2.microsoft.com/en-us/library/ms178472.aspx > this really is an excellent article and it is the one i was looking for
> earlier but couldn't find. well worth an afternoon of studying. they
> also give a few tips for nested databound controls under the heading
> "catch up events"
>
> i am stumped by the double Page_Load. i can't see how Page.Postback could
> be false unless you have some Response.Redirect code or some javascript to
> reload the page, or if your linkbutton doesn't directly cause a postback.
> i.e. if it is rendered as <a href="SamePage.aspx?Select=10">Select</a>
>
> can you post the aspx and code-behind? don't worry about the database
> connections etc, just by looking at the code it may be clear where the
> problem is.
>
> thanks
> tim
>
> "Steve Hershoff" <babbaloo@nowhere.com> wrote in message
> news:OnV$Yh4yGHA.3908@TK2MSFTNGP05.phx.gbl...
>> Thanks again Tim. You understand how the dropdown list and the session
>> variable interact.
>>
>> I guess I need to play around a little more. I suppose the way things
>> work is that when I click the LinkButton a postback is generated, then
>> the Page_Load is called. I assumed the LinkButton's Click() event
>> handler would be called even if the datagrid it resides in isn't bound
>> again, but it appears not?
>>
>> One more thing, if you don't mind another question. Would you happen to
>> know what events are fired or what happens in general on a page when a
>> DataBind takes place? I ask because in our Page_Load we're binding the
>> topmost datagrid every time, whether IsPostBack is true or not.
>>
>> The first time we enter this page the topmost grid is bound only once.
>> If I click on a hyperlink to "show the secondary datagrid," the Page_Load
>> method is called again, with IsPostBack set to true. So far so good.
>> Again, Page_Load binds the master datagrid.
>>
>> However, this time the page is immediately reloaded(?) (IsPostBack equals
>> false now) and the master datagrid is bound yet again. Only now is the
>> secondary datagrid loaded and bound.
>>
>> I don't understand why Page_Load is called twice in succession? I'm not
>> reloading or redirecting back to the page, at least not directly in my
>> code. Strange indeed.
>>
>> I keep trying to find good information on the page lifecycle. The
>> 4guysfromrolla.com site is great for workaday questions involving aspx,
>> but it's still tough. No two sources seem to agree on what happens.
>> Either that or they flood you with terms like PagePreRenderInit() and set
>> your head spinning. Do you happen to have any favored websites or books
>> that do a good job on this?
>>
>> Thanks again for all your help. I really appreciate it.
>>
>> -Steve.
>>
>>
>>
>>
>> "Tim_Mac" <tim.mackey@community.nospam> wrote in message
>> news:uyFJmjtyGHA.476@TK2MSFTNGP06.phx.gbl...
>>> hi steve, i'm trying to piece together the setup there.
>>>
>>> so the drop-down-list SelectedIndexChanged event fires because of your
>>> code that compares the session variable and updates the SelectedIndex of
>>> the menu accordingly. that one is explained then?
>>>
>>> if you only bind the secondary datagrid in response to a
>>> SelectedIndexChanged event, then the LinkButton Click event won't fire
>>> for that datagrid. you need to bind the secondary datagrid for each
>>> post back where you want to use events with it (especially on the
>>> Postback that occurs when you click the LinkButton).
>>>
>>> you're code should look something like this:
>>>
>>> public void Page_Load(...)
>>> {
>>> if(!IsPostBack)
>>> {
>>> // bind the topmost datagrid and other first time load stuff
>>> }
>>> else
>>> {
>>> // bind the secondary datagrid, dropdownlist, extra button
>>> column, etc.
>>> // exactly as you had it as of the last postback
>>> }
>>> }
>>>
>>> this approach works for me. if this doesn't give you any ideas, can you
>>> post your Page_Load and OnInit code, and anything else that affects the
>>> loading/binding of the dynamic controls. if it's worth it, you may like
>>> to create a stripped down version of the page and i could test it out
>>> here.
>>>
>>> cheers.
>>> tim
>>>
>>
>>
>
>