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

Home Posts Topics Members FAQ

Problem with Event handlers for Dynamic created Controls in DatGri

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

I am pasting below the pieces of my code for your better understanding.
//creating the dynamic control "lButton" at the footer in the ITEM DATABOUND
EVENT and assigning th events to it.
private void datagrid1_ItemD ataBound(object sender,
System.Web.UI.W ebControls.Data GridItemEventAr gs e)
if(e.Item.ItemT ype == ListItemType.Fo oter)
LinkButton lButton=new
lButton.Text ="Add Details
lButton.ID ="flagbutton ";
lButton.Command Name="flagButto n";
lButton.Click +=new System.EventHan dler(this.lButt on_Click);
e.Item.Cells[2].Controls.Add(l Button) ;


//in the ITEM COMMAND EVENT, executing the a logic when teh link button in
the grid gets clciked
private void datagrid1_ItemC ommand(object source,
System.Web.UI.W ebControls.Data GridCommandEven tArgs e)
if(String.Compa re(e.CommandNam e,"flagButton", true)==0)
Response.Write( "done");
private void lButton_Click(o bject sender, System.EventArg s e)
DataGridCommand EventArgs dgcea = (DataGridComman dEventArgs)e;
datagrid1_ItemC ommand(sender, dgcea);

so could anyone of you help me out in fixing the problem . and the reson for
this type of cause.

Your expert advice in sorting out thsi issue woudl be highly appreciated.


Nov 19 '05 #1
2 1545
You need to populate the datagrid on postback so that the button is

If the button is not recreated then the event will not be wired up

Nov 19 '05 #2
A few things come to mind:

*Why do you need to dynamically add the linkbutton to the datagrid?
Why can't you place the linkbutton into the datagrid at design time and
then simply set its visibility based on the situtation? Handling
events for controls added at runtime can be tricky as you need to pay
close attention to the sequence of page and control events.

*Is there anywhere in your code or tags where you specify that the
onItemCommand event for the datagrid will be handled by your procedure
datagrid1_ItemC ommand?

*Is the viewstate on your datagrid enabled?

*If you intend to trap and process the click event for your linkbutton
in the datagrid's ItemCommand event, why are you assigning a different
event handler (lButton_Click) to handle it?

*At what point in the page are you binding data to the datagrid and how
often? Are you rebinding with each postback?

Bill E.
Hollywood, FL

Nov 19 '05 #3

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

Similar topics

by: tony kulik | last post by:
This code works fine in ie and opera but not at all in Mozilla. Anybody got a clue as to how to get it right? <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <script language="JavaScript" type="text/javascript"> function show(that) { if (box.style.visibility=='hidden') { that.style.visibility = 'visible'}; }
by: Lamont Adams | last post by:
Hi all, I've created numerous custom controls of varying complexity, but I've been on this problem for a day and a half, and I can't figure this mystery out. I hope one of you kind folks can point out the really obvious and stupid thing I'm overlooking here. :) I have a custom control that provides a tasklist similar to what you get in certain parts of Office. On the client it consists of a bunch of nested, named and id'ed divs with...
by: Charles Law | last post by:
For some reason, when I click the X to close my MDI parent form, the action appears to be re-directed to one of the MDI child forms, and the parent remains open. I am then unable to close the application. What should happen, is that the main MDI form should close, taking the child forms with it. There is code to loop through the child forms, remove the controls on each of them, and then close the form, but this code should execute only...
by: Kris Palmer | last post by:
hi, can somebody explain this problem? it's driving me crazy! i have a requirement to dynamically create a variable quantity of timers with associated start button based on the contents of a database. if i create system timers dynamically, i cannot reference them from the start button click event handler. the build error is ' <timer name> not declared> ---- however, if i declare the system timers outside runtime code, everything works...
by: hlubocky | last post by:
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...
by: matt.grande | last post by:
Please, I REALLY need help with this one. I've been banging my head about it for three days now. Here's the situation. I have a form that runs some queries and functions and such. When all is said and done, there are several new controls (LinkButtons) on the page. Dynamicly created controls MUST be created in the Page_Load. Now, if I click one of the LinkButtons, the page attempts to reload
by: Spectre1337 | last post by:
Hello, I'm having huge difficulties solving what should be a relatively trivial problem. The following is a gross simplification (obviously it's not that simple in reality) but it will serve its purpose: I need to program a dynamically generated list, kind of like a shoutbox, that stores the messages in a Profile variable. I know, I know, the messages would be lost as soon as the session expires, but that'll be sufficient for this...
by: Dica | last post by:
i've got a script that loops through a dataset and creates dynamic web controls and event handlers: while (oDr.Read()){ RadioButton oRb = new RadioButton(); oRb.ID = oDr.ToString(); oRb.AutoPostBack = true; oRb.CheckedChanged += new System.EventHandler(this.clientRadioButton_click); }
by: Chris | last post by:
Hi, When choosing a value in the dropdownlist, i try to put that selectedvalue in the label, but i always get the first value 'a'. EnableViewState is by default set to true, so ... what's wrong in my code? Thanks Chris Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
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...
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...
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...
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...
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...
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();...
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...
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
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.