Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   ASP .Net (http://www.velocityreviews.com/forums/f29-asp-net.html)
-   -   Missing LinkButton click events (viewstate problem) (http://www.velocityreviews.com/forums/t116362-missing-linkbutton-click-events-viewstate-problem.html)

hlubocky@gmail.com 12-29-2005 04:18 PM

Missing LinkButton click events (viewstate problem)
 
I thought I had a good grasp of the problem related to dynamically
creating controls, but it appears that as my application grew in
complexity, the problem has resurfaced. As I understand it, in order
for a dynamically created control to persist its state, it needs to be
created and loaded into the page control hierarchy before the viewstate
is loaded.

The proposed solution, and that which I have been using, has been to
create all of the needed controls in the OnInit, and then when they are
going to be rendered, they will have the appropriate state set by the
loading of the viewstate. This also appears to affect when events are
received on postback. That is, if the control has been created before
viewstate is loaded, then an event on that control will correctly be
received.

My problem is that the dynamic creation of some controls depends on the
values persisted in the viewstate of other controls. This means that I
am unable to create all of the correct controls in OnInit since I don't
know exactly which to create. Here is an example. I have a Table that I
construct myself and render (no bound datagrid). The number of rows to
render depends on the paging settings retrieved when the viewstate is
loaded. If all of the content is text, then it doesn't matter. The
problem is that one column consists of LinkButtons, and if I don't
create the correct subset of the linkbuttons OnInit, then when they are
clicked by the user, the event won't be received on postback. (ie
default paging settings include 50 rows. When I disable default paging
to show say 100 rows, clicking any of the first 50 linkbuttons works
fine, but any after that (which aren't created in OnInit) don't.

Am I understanding the problem correctly? Is there a better solution?
The one I see at the moment is to create all possible LinkButtons in
OnInit(). I have a feeling my limited knowledge of ASP.Net is to blame
here.

Thanks,
--Brian


Remy 12-29-2005 04:32 PM

Re: Missing LinkButton click events (viewstate problem)
 
Not sure if this is obvious, but why don't you use a datagrid? You can
include LinkButtons in a datagrid and also receive events from them and
then figure out from which button the event came.
So, its all there. Do I miss something?

Remy Blaettler
http://www.collaboral.com


hlubocky@gmail.com 12-29-2005 04:41 PM

Re: Missing LinkButton click events (viewstate problem)
 
I need to format the text, background, etc for each column (and
sometimes cell) differently depending on the value, and I didn't see
that level of control available in the stock datagrid. Instead I went
with the option to just draw the grid myself, which gives me everything
I need in terms of formatting, though it might be killing me as in the
problem described above.


Remy 12-29-2005 04:56 PM

Re: Missing LinkButton click events (viewstate problem)
 
You can do that too with a datagrid. They are really powerful. I would
suggest reading a tutorial about the datagrid. You can define your own
templates that do conditional formating, etc.


hlubocky@gmail.com 12-29-2005 05:01 PM

Re: Missing LinkButton click events (viewstate problem)
 
I guess its worth a look, though I am more interested in testing my
understanding of the problem described. Am I correct in my assumptions?
Am I misunderstanding the problem? etc..


Bruce Barker 12-29-2005 05:12 PM

Re: Missing LinkButton click events (viewstate problem)
 
you are confusing viewstate with postback data. viewstate is a hidden field
that control can use to store properties across a postback. postback data is
the data the browser send back on a post (this includes the viewstate). for
a control to receive its postback data, it must be created before form load.

now for any dynamic control to access viewstate of receive it correct
postback data, it not only must be re-created on postback, it must have the
same name. if its a child, its parent must be created (with its proper
name).

if you want asp.net to correctly handle you dynamic control, in all cases,
you should always recreate all of then on postback in the onint event.
viewstate is a good place to store any info you need to recreate them.

-- bruce (sqlwork.com)


<hlubocky@gmail.com> wrote in message
news:1135873095.226824.52610@o13g2000cwo.googlegro ups.com...
>I thought I had a good grasp of the problem related to dynamically
> creating controls, but it appears that as my application grew in
> complexity, the problem has resurfaced. As I understand it, in order
> for a dynamically created control to persist its state, it needs to be
> created and loaded into the page control hierarchy before the viewstate
> is loaded.
>
> The proposed solution, and that which I have been using, has been to
> create all of the needed controls in the OnInit, and then when they are
> going to be rendered, they will have the appropriate state set by the
> loading of the viewstate. This also appears to affect when events are
> received on postback. That is, if the control has been created before
> viewstate is loaded, then an event on that control will correctly be
> received.
>
> My problem is that the dynamic creation of some controls depends on the
> values persisted in the viewstate of other controls. This means that I
> am unable to create all of the correct controls in OnInit since I don't
> know exactly which to create. Here is an example. I have a Table that I
> construct myself and render (no bound datagrid). The number of rows to
> render depends on the paging settings retrieved when the viewstate is
> loaded. If all of the content is text, then it doesn't matter. The
> problem is that one column consists of LinkButtons, and if I don't
> create the correct subset of the linkbuttons OnInit, then when they are
> clicked by the user, the event won't be received on postback. (ie
> default paging settings include 50 rows. When I disable default paging
> to show say 100 rows, clicking any of the first 50 linkbuttons works
> fine, but any after that (which aren't created in OnInit) don't.
>
> Am I understanding the problem correctly? Is there a better solution?
> The one I see at the moment is to create all possible LinkButtons in
> OnInit(). I have a feeling my limited knowledge of ASP.Net is to blame
> here.
>
> Thanks,
> --Brian
>




hlubocky@gmail.com 12-29-2005 05:20 PM

Re: Missing LinkButton click events (viewstate problem)
 
In my situation I have a text box that the user can enter the number of
rows to display in my custom Table. For each row I create one
LinkButton. Am I understanding correctly that in order for the clicked
event to be received on the LinkButton, it must be created in OnInit
with the same name as it did before the post? In this case I don't know
the number of rows the user wants to display until AFTER the viewstate
is loaded.

I'm trying to figure out if the way to handle this is to create one
LinkButton for every row in the dataset OnInit and then OnLoad just
create the ones I need to handle the paging? This seems a little
wasteful as I can have up to 2000 rows max.

Thanks,
Brian



All times are GMT. The time now is 03:18 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.