Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Missing LinkButton click events (viewstate problem)

Reply
Thread Tools

Missing LinkButton click events (viewstate problem)

 
 
hlubocky@gmail.com
Guest
Posts: n/a
 
      12-29-2005
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

 
Reply With Quote
 
 
 
 
Remy
Guest
Posts: n/a
 
      12-29-2005
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

 
Reply With Quote
 
 
 
 
hlubocky@gmail.com
Guest
Posts: n/a
 
      12-29-2005
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.

 
Reply With Quote
 
Remy
Guest
Posts: n/a
 
      12-29-2005
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.

 
Reply With Quote
 
hlubocky@gmail.com
Guest
Posts: n/a
 
      12-29-2005
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..

 
Reply With Quote
 
Bruce Barker
Guest
Posts: n/a
 
      12-29-2005
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)


<(E-Mail Removed)> wrote in message
news:(E-Mail Removed) 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
>



 
Reply With Quote
 
hlubocky@gmail.com
Guest
Posts: n/a
 
      12-29-2005
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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Mobile, LinkButton, Grid 'Select' click events not working on clie Mike McAllister ASP .Net Mobile 11 02-21-2006 05:42 AM
Linkbutton does not look like a linkbutton Sathyaish ASP .Net 3 09-08-2005 09:41 AM
Linkbutton does not look like a linkbutton Sathyaish ASP .Net Datagrid Control 1 09-08-2005 08:44 AM
Events Events Events Please Help Chris ASP .Net Web Controls 0 08-30-2005 08:21 PM
Button Click events only firing on second click Ben Fidge ASP .Net 5 06-15-2004 02:28 PM



Advertisments