473,854 Members | 1,573 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

Dec 29 '05 #1
6 2867
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

Dec 29 '05 #2
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.

Dec 29 '05 #3
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.

Dec 29 '05 #4
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 misunderstandin g the problem? etc..

Dec 29 '05 #5
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)
<hl******@gmail .com> wrote in message
news:11******** *************@o 13g2000cwo.goog legroups.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

Dec 29 '05 #6
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

Dec 29 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
13576
by: Assaf Weinberg | last post by:
Using ASP.NET web form with VB.NET I have a page with a calendar control that onSelectionChanged builds a table control showing the events scheduled for the selected calendar days. One of the columns in this table contains linkbuttons that, when clicked, should execute some code (currently an event handler called showEvent) that displays details. I am currently using addhandler to specify the handler for
3
10813
by: Kiyomi | last post by:
Hello, I create a Table1 dynamically at run time, and at the same time, I would like to create LinkButton controls, also dynamically, and insert them into each line in my Table1. I would then like that, when clicking the LinkButton, the user can be navigated to another page, carrying a variable. I would like to use server.transfer method instead of QueryString as I don't want the carried variable to be visible for the user.
1
8189
by: Earl Teigrob | last post by:
PROBLEM: When a user control is loaded into a PlaceHolder control more than once, the events do not fire on the first click of a control on the dynamically loaded user control. In other words, the first time the control is dynamically loaded, everything works fine. After that, if the control is loaded again from the page button event handler, the user controls events fail to fire on the first click NOTE: I (believe I) am rebuilding all...
10
2863
by: Bharat | last post by:
Hi Folks, Suppose I have two link button on a page (say lnkBtn1 and lnkBtn2). On the click event of the lnkbtn1 I have to add a dynamically created control. And On the click event of the lnkBtn2 I have to add a datalist control. Using this datalist control I should be able to add edit, modify and cancel the items listed in this control. Here is how I designed. I used placeholder to add the controls dynamically to the page on the click...
5
1822
by: Steve Harclerode | last post by:
Here's some code that I'm using to create a simple list of logical drive letters (my web application impersonates a user). I'm finding that my event handler doesn't fire. Can anyone give me a hint as to why it doesn't work? It's nearly a copy of some sample code that I lifted from a friend, whose code works (so he says!). By the way, I'm using a dotnet Table control in the ASPX page which starts off empty, it's ID is dirTable. By the...
2
1422
by: prashant khandalkar via DotNetMonster.com | last post by:
Hello everyone. I am using asp:linkbutton in my web page. But when i click on the linkbutton it is not firing the click event please help me. It's urget my email address is pkhandalkar@gmail.com. -- Message posted via http://www.dotnetmonster.com
4
10614
by: Fueled | last post by:
Hi everyone! I've made quite a lot of research on this, and I've tried a couple of proposed solutions. Nothing has worked for me, but I feel there's not much I'm missing. So I'm turning to this group and its experts for answers. So : - I've got a main page (main.aspx) - On this page, I've got a button (btnArchive), on whose click I dynamically add a UserControl (archive.ascx) to the main page.
1
1178
by: hiuentsang | last post by:
Hi, How can I access the event generated by the click on a linkbutton in a datagrid? My requirement is like this... I've placed a linkbutton in a datagrid. The user clicks on it, and some value is stored in the ViewState. I am not able to capture the event of click. Please Help. Thanks & Regards
3
4078
by: MRW | last post by:
I have a simple linkbutton and a function when it's clicked. It works perfectly in a regular .aspx page. However, when I place it inside the ContentPlaceHolder, it no longer works. It does *something*, but certainly not the function, which is also in the ContentPlaceHolder. This is also true concerning any events in there. Any ideas? Thanks for any help!
0
9901
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
11025
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10682
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9513
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
7082
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5743
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5942
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4562
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4159
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.