473,657 Members | 2,266 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Dynamic LinkButton, ViewState

I have a <asp:table> control with a large number of dynamically created
LinkButtons. I am using the command event, command name and command argument
values in my LinkButtons to trigger actions after the post back. The table
is dynamically generated based on a key field that is stored in ViewState.
This key field is updated by several other controls on the same page.

I am struggling with the pattern of when to create the table. I can't load
it in Page_Init as ViewState is not restored. If I load it at Page_Load
time, I seem to be getting the command name/arguments from the previous
postback and at times, my dynamic LinkButton fails to fire the command
event.

Any suggestions would be appreciated. Thanks,

Andrew
Jun 16 '06 #1
1 2497
Hi,

generate it so that you create controls in page_load, but set any proeprties
after you have added the control to Controls collection so that ViewState
tracking has started. And such, state dependant properties need to be set
only once inside If Not IsPostBack check (!IsPostBack in C#), e.g
initially..

here are a some references

Understanding ASP.NET ViewState
http://msdn.microsoft.com/library/de.../viewstate.asp
Dynamic Web Controls, Postbacks and ViewState
http://aspnet.4guysfromrolla.com/articles/092904-1.aspx
Dynamic Controls in ASP.NET
http://aspnet.4guysfromrolla.com/articles/081402-1.aspx
Working with Dynamically Created Controls
http://aspnet.4guysfromrolla.com/articles/082102-1.aspx

--
Teemu Keiski
ASP.NET MVP, AspInsider
Finland, EU
http://blogs.aspadvice.com/joteke
"Andrew Robinson" <ne****@nospam. nospam> wrote in message
news:ub******** ******@TK2MSFTN GP03.phx.gbl...
I have a <asp:table> control with a large number of dynamically created
LinkButtons. I am using the command event, command name and command
argument values in my LinkButtons to trigger actions after the post back.
The table is dynamically generated based on a key field that is stored in
ViewState. This key field is updated by several other controls on the same
page.

I am struggling with the pattern of when to create the table. I can't load
it in Page_Init as ViewState is not restored. If I load it at Page_Load
time, I seem to be getting the command name/arguments from the previous
postback and at times, my dynamic LinkButton fails to fire the command
event.

Any suggestions would be appreciated. Thanks,

Andrew

Jun 17 '06 #2

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

Similar topics

0
1375
by: Tomas Vera | last post by:
Here's another goofy thing. I need to persist the state of items added dynamically to a Panel control between round-trips to the server. I have a web form that contains a TreeView and a DropDownList My web form reads the value of the drop down list, runs a query against a database, then presents the results of the query to the user with a TreeView (IE WebControls version). When the user checks an item's checkbox, the item is
10
2844
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...
2
1535
by: Shiju Poyilil | last post by:
I have a link button "lButton" created dynamically at the item databound event of the data grid "datagrid1" in the footer.so i want to execute the item command event of the datagrid on clicking the dynamicaly created link button, but when at runtime i click the dymanic created control it disapears from the datagrid footer and then it doesnt fire the itemcommand event of the datagrid. I am pasting below the pieces of my code for your...
2
2171
by: cindy | last post by:
I have a web form with 3 links, depending on which link is clicked a user control loads, page1.ascx,page2.ascx,page3.ascx page1.ascx does a search, uses 3 asp:dropdownlists with viewstate true and auto post back. It loads by default first time. User clicks on link 2, page2.ascx loads after page1.ascx I need the loaded control to go away when a different one is clicked, I have seen similar stuff on threads but I can't understand a...
6
1434
by: Andrew Robinson | last post by:
I have a page that contains a number of link buttons that are used for making selections. I load my LinkButtons during the Page_PreInit event and they render fine but then I need to make a change to one of these LinkButtons depending on the selection. I am using the Command Event and passing a key in the Command.Name field. From within this even handler, I am clearing my LinkButtons and then re-redering and marking with a different...
1
3701
by: JeffP | last post by:
I need to know when a link buttons value is zero so I don't try to run a query to find none. When I was using ViewState(ds_Last), which I can't do because certain phones are choking on the data, I have on avg about 12 rows of data. Apparently that's way too much data for some phones, nearing 30k. So I've abondoned ViewState and I'm trying to get the value from the datagrid, I see that it can be done but I may be missing something...
13
10162
by: rn5a | last post by:
In a shopping cart app, suppose a user has placed 5 orders, I want to show him 5 LinkButtons (one for each order) so that when he clicks the first LinkButton, he would be shown the details of his first order. Likewise if he clicks the second LinkButton, he will be shown the details of the second order he had placed. The Text of the LinkButtons will be 1 2 3 etc. So this user would see 1 2 3 4 5 as the LinkButtons. The problem is...
6
2590
by: ree321 | last post by:
I have a linkbutton which is added to a column in a datagrid dynamically using a template I created. When I change the data in it by not databinding and then when I later retreive the data from the control after a post back it goes back to the value which was dynamically bounded. I have set up similar process with a checkbox template and it remebers the value. Are Linkbuttons not capable of this? and should I use something else?
0
258
by: danielhamd | last post by:
Hello - I am having some trouble with dynamic controls in Asp.Net. I have a form for a user to enter certain information. When this information is posted back, it is shown on the page by creating dynamic labels in a table, and also putting a dynamic link button "remove" for each entry. I create the controls in the Page_Load function, so that I can wire up the remove linkbutton to have a command event (that passes the index
0
8407
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
8837
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
8739
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...
1
8512
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8612
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
4171
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
4329
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2739
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
1732
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.