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 button to the containers control collection, the event handler is called. However the same code runs in the old ASP.NET 1.1 and Sharepoint 2003 environment.

Can somebpdy please help with this? Is there anything which has changed from ASP.NET1.1 to 2.0 which is causing this?

0
irtaiza
11/12/2008 3:59:45 PM
asp.net.personalization 3779 articles. 0 followers. Follow

1 Replies
792 Views

Similar Articles

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

Well Thank GOD and to a dear friend with whose help we were able to resolve the issue. Thanks a ton Vijeta. You deserve a party and you will be treated soon.

The scenario was that the button was getting added dynamically and event handlers were not getting called. What we missed out on was assigning an "ID" to the button. Since the controls were conditionally getting added to the webpart, the "ID"'s which ASP.NET assigns to the controls were not consistent. So initially the button "ID" was "_ctrl5" and on postback since some of the controls were not created the button "ID" was "_ctrl3". So we believed the event handler is not getting called because of this. We simply assigned an "ID" to the button in the code and it worked.

We have similar webparts with many buttons in different rows but with same name. These were also getting added dynamically and since the time we have assigned them an "ID", everything is working fine.

Sad part 1--> I have never found a mention on any of the sites about this, that you need to assign an "ID" always to a control inorder to handle it's event. I have found posts where people have experienced similar issues but no one gave the solution.

Sad Part 2 --> The same code "one without ID's" still works on the old version, that is, ASP.NET1.1/SharePoint2003. How does this work is still a question? If It was a bug then why wasn't it ever published that such a bug is fixed in ASP.NET 2.0.

Good Part --> We have resolved the issue and I have also provided a solution on this post for people like us who suffer because of some undocumented feature/bug.

Will appreciate comments from people who faced or are facing this issue. Or if anyone has links to any documentation or web where anything related to this is mentioned, please provide a link.

Thanks again, Vijeta.

Regards,

Irtaiza

0
irtaiza
11/13/2008 10:51:45 AM
Reply:

Similar Artilces:

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 ...

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...

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...

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...

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...

Cannot get a click event fired for a dynamic button...
Hello all, I am pulling my hair out trying all sorts of different ways to do what seems so simple.I have been searching numerous forums seeking the answer but none have worked. I am not completely new to programming but relatively new to .Net.I have created a user control that generates a file upload panel in code. It is a panel that dynamically creates its controls at run-time. The reason I generate controls in code is that i need to change the file-upload display depending upon which page calls it.Here is the entrie code for analysis: Partial Class fileLoader    Inherit...

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...

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...

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...

Dynamic button's Click Event in Grid view is not getting fired
 Hi All,I am a new bee for ASP.NET.  I have a small library web page, one of the page lists the all available books, when user want to add a book, I create a row with text boxes and Update, Cancel LinkButtons.On clicking on Update button, I am going to add those information into my database. The problem here is for Update, Cancel link buttons Click event is not fired.I have been looking in this forum to get a solution. Nothing worked with my situation.  Thanks in Advance.    protected void btnBook_Click(object sender, EventArgs e)    {  ...

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

Placebase team at Apple file “Schematic Maps” patent dynamically detailing important data
In a report from Computerworld way back in 2009, we learned that Apple had quietly acquired Maps API company Placebase. Then, founder of Placebase ...

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 ...

In a dynamically typed language, is it a bad idea to return different data types?
In some cases, returning different types from a single function works.

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/17/2016 4:32:00 PM