Button click event not fired for a custom webpart where controls are added dynamically.

We are migrating a Sharepoint 2003 site to MOSS 2007 and ASP.NET 2.0. We have also migrated the webparts but they are still inheriting from Sharepoint.WebPart. We have a webpart where controls are added dynamically at runtime. On this webpart a button is added dynamically and a click event handler is also attached. The button on the webpart is displayed only when there is some data. The button deletes the selected row of data when clicked. But when we click on the button, the page gets posted but the event handler is not called. We analysed and found that the code where we add the button to one of the table cells does not get executed. That means that the button is added to the webparts control collection but not to any other container's control collection and hence not added on the webpart. The button does not get displayed and event is also not handled. When we add the button forcefully to one of the container table, the event gets executed. Where are we going wrong? Or Is it an ASP.NET 2.0 limitation.

Please note that this same code works extermely fine in ASP.NET 1.1 and Sharepoint 2003.

Any help will be highly appreciated. Thanks.


11/12/2008 3:22:51 PM
asp.net.personalization 3779 articles. 0 followers. Follow

8 Replies

Similar Articles

[PageSpeed] 19
Get it on Google Play
Get it on Apple App Store

I didn't see the code so can't say what exactly the problem it is.

But develop customization webpart under Sharepoint 2003 and ASP.NET is NOT same as developement under Sharepoint 2007. Under 2007 the webpart are inheriting the namespace System.Web.UI.WebControls.WebParts.

So please read through this article http://www.wrox.com/WileyCDA/Section/Developing-SharePoint-2007-Web-Parts.id-306330.html

Hope this one helps.

Best Regards,


11/13/2008 10:38:42 AM

Thanks Ji for the response.

I have been able to resolve the issue. Please see my other post for the resolution. What I found out was that the code was not assigning any ID to the dynamically added controls and since some of the controls were not generated always, the ID's generated by ASP.NET were also not consistent for same control on Postback. The moment we assigned the "ID' to all the controls, everything started working fine.

 The big question before us is why is it working in the older version ASP.NET1.1 and Sharepoint 2003? Can you provide something on this?




11/13/2008 11:02:27 AM

It seems to be a typical convert ASP.NET 1.1 to ASP.NET 2.0 issue. Check these post out:



Hope this can help you guys get some idea.



11/13/2008 11:22:41 AM

Thanks a lot Ji. The inputs are really helpful.

11/14/2008 6:18:29 AM

Hello Irtaiza. I am facing the same issue in .net 3.5. I have created a web part which has few text boxes and labels and a save button. I have assigned an id to the save button. On deploying this web part, and opening it, I am able to debug it. However, the save button click event is just not being fired. I am just stuck up with this. Please let me know if there is anything that I am missing. Thanks.


11/26/2008 10:50:34 AM

hey snehal,

sorry for being late ..... Can you confirm that you have attached an event handler for your button. Thats somewhere in your intialization section u must have this code

button.click += new EventHandler(button1_click);

Make sure this is there.

11/27/2008 10:08:12 AM

Hello irtaiza. I have solved the issue. Actually I was accessing an object (A class in different assembly) in my event handler. On removing the code which accessed the object, my event handler started firing properly.

I have no clue about why the event handler didn't fire earlier. I also ensured that object's assembly was strong named and installed to the GAC.Even then it didn't fire.I have worked around this problem by moving the class to the same assembly.




11/27/2008 10:20:38 AM

That's cool!!!

11/27/2008 3:50:56 PM

Similar Artilces:

Button click event not getting fired for a custom webpart where controls are added dynamically.
 We are migrating from ASP.NET1.1/Sharepoint 2003 to ASP.NET 2.0/Moss 2007. We have a webpart on which controls are getting added dynamically. We have a button which is also dynamically added and a click event handler is also attached to it. However when we click on this button the page gets posted but the event is not fired. We analysed and found that the code to add the button in the webparts controls collection is executed but the code to add the button to it's container (that is a table) is not getting executed. Hence the event is not getting handled. If we forcefully add the bu...

button click event not firing for dynamic buttons added on PreRender of the updatepanel
Hi,i have a webpage with an updatepanel updatepanel1.i am adding controls dynamically to the updatepanel on the prerender event.i am using the prerender event as i want to get the latest bata from thedatabase which include the data i have inserted on my last button click.But the button click event is not getting trigged on clicking the button.Here is the sample code in PreRenderSqlCommand cmd = new SqlCommand("SELECT Heading, ID FROM tblNews ORDER BY ID;", conn);conn.Open();SqlDataReader sqlData =cmd.ExecuteReader(CommandBehavior.CloseConnection);while (sqlData.Read()){lblHeading =...

Dynamic custom control on custom control
What I'm trying to do is create a module for use within a larger page.  The page itself is an order form, which will have typical payment info (address, credit card, etc.), and the ability to select what you are paying for.  Our clients will have several options in how they want the page setup.  They can either have a single form, or they can have each module on it's own page.  They can also have all the selected items fire in a single transaction, or have a seperate transaction for each item selected.  And they can limit the total number of transactions a person can...

Dynamically loaded user control with a button doesn't fire its button click event?
I have a datagrid, in which one of the columns is 'button' column called 'Send Email'. When I click on this button, then an email user control is dynamically loaded into a placeholder above the datagrid header area. The email control renders correctly, but when I click on 'Send' button in this user control, then the click event of this 'Send' button doesn't fire. This is even though the 'Handles.btnSend.Click' is there for the click method of the 'Send' button. Can someone please tell me why the event is not firing and what do I need to do to make it fire?    sun21170 you have...

Dynamically adding User Control instances on Button click event
Hi All:  I have a user control which has three text boxes in it. Now I have a page where there is a place holder and a button. On the click event of the button I add an instance of the user control to the place holder. It works fine the first time and the user control is added to the place holder. However when I click again, a new user control instance is added and the first instance is not there... same thing is repeated if I click again...new instance is added and none of the previous ones are ther ein the place holder. The code for the web page is as follows:int iTextBoxUserControlC...

getting postback events to fire for dynamically added custom controls
I recently posted regarding these 2 controls, but this is a completely different issue, so I thought it best to start a new thread. I have two composite controls (neither renders content, rather they add controls to the control tree). Control X is declared on the page and is passed a custom collection. X iterates through this collection and creates a tab and a 'pane' for each item in the collection. To each pane it adds an instance of control Y, which contains a couple of textboxes and a hidden inputbox. My problem is: if I have a std button on the page which posts back, I need t...

Button in dynamic user control need to be clicked twice to fire event?
I have created a website that uses dynamic user controls. I placed a button in a dynamic user control but its need to be clicked twice to fire event. First click doesn't work, but subsequent clicks work. What should I do? Here is my code snippets:  default.aspx---------------------------------------------------------------------- <asp:Panel ID="Panel1" runat="server"></asp:Panel> <asp:Button ID="btnAnaSayfa" runat="server" Text="AnaSayfa" onclick="btnAnaSayfa_Click" ...

User Control Button Click Event Does Not Fire With Postback, when Loaded Dynamically
My application consists of a web form (MainForm.aspx) with a PlaceHolder (phMain) with several user controls that are loaded and removed dynamically based on the context. Two of these controls are LoginUC.aspx and DataEntryUC.ascx. Each of these controls have a 'Submit' button.When the application is launched, LoginUC is loaded to the PlaceHolder. Users enter an Id and Password, then upon authentication an event named  LoginCompleted.is raised in LoginUC. This event (LoginCompleted) is consumed in the parent form (MainForm.aspx) wherein the LoginUC control is removed...

Dynamically Added controls (buttons) to a GridViewRow on RowDataBound not firing RowDataCommand event
I have a GridView.  On the RowDataBound I create and add 1-N buttons into a column of the row.  I set the CommandName and CommandArguments accordingly.  The grid displays and the appropriate buttons display on each row, however when I click them I am expecting that they will fire the RowDataCommand event but they are not.  The buttons just disappear from the grid and the RowDataCommand never fires.  So somehow I need to hook each buttons command event to the existing datarows RowDataCommand event.  Any ideas how to do that? Thanks, Robb You could do somethi...

Table Cell click event
Hi, I used to have a custom server control inhirted from TableCell control to implement click event in VS.NET 2003.  When I use the custom control in VS.NET 2003 Web application (dynamically adding to table object), everything works fine.  Below is the code from 2003 project, and everything works good in this way.                 Dim c As New MyCustomTableCell                  c.Width = 200     &nb...

Button click does not fire inside a user control which is added dynamically to a ModalPopupExtender target
Hi All, I have a panel in the masterpage which has a modalpopupextender control associated to. There is a place holder inside the panel to which i dynamically add User Controls on the click of a LinkButton which resides somewhere on the page. The control gets added to the popup and the popup shows up. However when I click a button inside the User Control, its server click event does not get fired.. in turn the Master page's Page Load is fired. I forgot to mention that the link button, panel and modalpopup extender are inside a Update Panel. Following is the code snippet:&nbs...

Button Event Inside User Control Not Firing when Dynamically Created and added to Page.
Hello, I am dynamically Loading multiple instances of a UserControl and adding them to the Page.Controls collection. When I run the page the dynamically created Usercontrols are displayed with the proper data. However, when I click a LinkButton I have included in the UserControl to hide certain elements within the User Control the Page Posts back but the LinkButton.Click event does not fire inside the User Control. Further, if I just hard code the user control into the aspx file (giving me just the one instance) and I click the LinkButton the Click event does fire ins...

dynamically added linkbutton control, click event firing but cannot get page to open in iframe
I have a dynamically added linkbutton control (sorry for code layout, i get a noxmlhttp error when trying to use the source code box for posting) added like so: Private Sub AddSecondLevelLinks(ByVal theTitle As String, ByVal theUrl As String) Dim lb As New LinkButtonlb.Text = theTitle lb.ID = lb.Text lb.CommandArgument = theUrl lb.Visible = True lb.CssClass = "secondLevel"Panel2.Controls.Add(lb) AddHandler lb.Click, AddressOf SecondLevelButtonClickEnd Sub When i click the button my eventhandler definitely fires (drops in here in debug) but does not work as expe...

Event not firing with Dynamic Controls in a Custom Web Control
I'm creating some LinkButtons on the fly (on Load) and they show up just fine.  The problem is that the AddHandler event I created is not firing.  I'm at a loss...have read a ton of articles today, but just can't figure this one out.  Please help a newb! :-)Protected Overrides Sub OnLoad(ByVal e As System.EventArgs) MyBase.OnLoad(e) EnsureChildControls() If Me.Page.IsPostBack Then Me.Units = Me.rblUnits.SelectedValue 'If there is text in the txtSearch TextBox, then search for the new loc...

Web resources about - Button click event not fired for a custom webpart where controls are added dynamically. - asp.net.personalization

iPhone 5 A6 chip to dynamically up-clock up to 1.3GHz (and downclock too)?
Interesting video from our friends at TLDToday: If this is not just a Geekbench app glitch, it could indicate why that A6 processor is so 2X ...

Apple's Lightning port dynamically assigns pins to allow for reversible use
... a closer look at how Apple's new Lightning connector works, and has come to the conclusion that the 8 pins on each side of the plug are dynamically ...

iPhone 5 Lightning port dynamically reassigns pins
... of Apple's Lightning USB cable shows that the pins on the plug aren't arranged symmetrically, suggesting that the Lightning port can dynamically ...

Urlbox Launches Screenshots-as-a-Service Platform to Dynamically Update Galleries
... changes. Launched yesterday, Urlbox allows anyone with a gallery displaying website screenshots to automate the process and keep them dynamically ...

Everything.me launcher dynamically adapts to what you’re doing right now
... phone according to what you’re doing. Perform a search for ‘football’ and your background will change to the NFL logo. A launcher that dynamically ...

A YouTube Experiment Resizes the Player Dynamically
There's a new YouTube experiment that changes the video player's size, depending on the browser window's size. When resizing Chrome's window, ...

Apple Granted “Dynamically Changing Cursor for User Interface” Patent, Originally Filed in 2003
... a utility patent that covers the use of the mouse cursor that changes according to the context of the task it is engaged in. Called a “Dynamically ...

Atmel's FPSLIC II Dynamically Reconfigurable SoC Supports "Silicon-Sharing" For Peripherals & Interfaces ...
Silicon-Sharing Fits 200K Gate Design into 40K Gate FPSLIC II's, Cuts Power Drain by 97%

Everything.me Launcher Wants to Dynamically Change Phones Based on Location, Interests, and Mental State ...
What if your phone’s launcher dynamically changed based upon interests, your location, or topics you had in mind at a specific moment? A new ...

Resources last updated: 1/4/2016 7:20:55 AM