Click event not fired for dynamic image button


   I have created one website with master and content pages ...On Master page I have created some dynamic image button controls on load event

i have created array of image buttons and taken one placeholder on web page then i have added image buttons on placeholder with while loop and added placeholder on web page .

    but my problem is that the click event for dynamic generated image button is not fired , it is like Unreachable code.

my code on master page is

protected void Page_Load(object sender, EventArgs e) 



    ...some database and other code 


HtmlTableRow htr = new HtmlTableRow();
        htr.ID = "Row_Service";

        string imgPath;
        while (k < row_counter)

            HtmlTableCell htc = new HtmlTableCell();
            htc.ID = "Cell" + k;
            htc.BorderColor = System.Drawing.Color.Crimson.ToString();
            htc.Width = "2";
            img[k] = new ImageButton();
            LB[k] = new Label();
            img[k].Attributes.Add("runat", "server");
            img[k].ID = dsimg.Tables[0].Rows[k]["ClassId"].ToString() + ":" + dsimg.Tables[0].Rows[k]["ServiceId"].ToString();
            imgPath = Server.MapPath(dsimg.Tables[0].Rows[k]["Service"].ToString());
            img[k].ImageUrl = imgPath;
            img[k].Height = 100;
            img[k].Width = 100;
            img[k].CommandArgument = "Type" + k;
            img[k].CommandName = dsimg.Tables[0].Rows[k]["Service"].ToString();
            img[k].Click += new ImageClickEventHandler(DesignMaster_Click);


            //aImageButtons.Add("img" + k);
            //Session["ImageButtons"] = aImageButtons;
            k = k + 1;



  void DesignMaster_Click(object sender, ImageClickEventArgs e)
        ImageButton im = (ImageButton)sender;
        Session["Id"] = im.ID;


      001pt; mso-pagination:widow-orphan; font-size:12.0pt; font-family:"Times New Roman"; mso-fareast-font-family:"Times New Roman";} @page Section1 {size:8.5in 11.0in; margin:1.0in 1.25in 1.0in 1.25in; mso-header-margin:.5in; mso-footer-margin:.5in; mso-paper-source:0;} div.Section1 {page:Section1;} --> /* Style Definitions */ table.MsoNormalTable {mso-style-name:"Table Normal"; mso-tstyle-rowband-size:0; mso-tstyle-colband-size:0; mso-style-noshow:yes; mso-style-parent:""; mso-padding-alt:0in 5.4pt 0in 5.4pt; mso-para-margin:0in; mso-para-margin-bottom:.0001pt; mso-pagination:widow-orphan; font-size:10.0pt; font-family:"Times New Roman"; mso-ansi-language:#0400; mso-fareast-language:#0400; mso-bidi-language:#0400;}



So can any one know how to solve this problem............Thanks in advance..


Normal 0 false false false MicrosoftInternetExplorer4 /* Style Definitions */ table.MsoNormalTable {mso-style-name:"Table Normal"; mso-tstyle-rowband-size:0; mso-tstyle-colband-size:0; mso-style-noshow:yes; mso-style-parent:""; mso-padding-alt:0in 5.4pt 0in 5.4pt; mso-para-margin:0in; mso-para-margin-bottom:.0001pt; mso-pagination:widow-orphan; font-size:10.0pt; font-family:"Times New Roman"; mso-ansi-language:#0400; mso-fareast-language:#0400; mso-bidi-language:#0400;}  

1/2/2009 11:09:06 AM 93655 articles. 6 followers. Follow

1 Replies

Similar Articles

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

 Are you creating these dynamic controls inside the If(!ispostback) condition, If yes, then you need to remove the condition and create the dynamic controls even on postback...


Please mark the answer if it helped you
1/2/2009 11:41:28 AM

Similar Artilces:

Web Parts & GridView button, link image click events does not fire on IE 7.0
 Hi,I have created a sample web app for testing in .NET Framework 3.5, used web parts added grid view into web part on the page to display the data. the button & link click events on these controls does not fire on IE 7.0 such as edit, select, delete,  buttons, paging & sorting in GridView and web parts restore button click events.I have executed the same application on Fire Fox browser, which is working fine.Please help me in fixing the problem how to run the same on IE 7.0 Shyam Sundar Hi shyam_eg, It should work . I strongly suspect you have disabled javascript . So please check , Open Internet Explorer. Select Internet Options from the Tools menu. In Internet Options dialog box select the Security tab. Click Custom level button at bottom right. The Security settings dialog box will pop up. Under Scripting category check Active Scripting Check radio boxes. Click OK twice to close out. Samu ZhangMicrosoft Online Community SupportPlease remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. ...

An OnClick event doesn't fire up when a button is clicked in a Tab Panel in a Tab Container in an AJAX Web Form
Hello Post: I would like to enclose the following code so you can analize what is going on: "> " style="vertical-align:top;"> "> "> " CausesValidation="False" onclick="btnOK_Caller_Click" /> " CausesValidation="False" onclick="btnCancel_Caller_Click" /> " style="vertical-align:top;"> "> " WatermarkCssClass="watermarked" Enabled="True"> ">* ...

Image button .click event not firing the first time clicked
I have an image button that saves a record to my backend. It has the CausesValidaton property = "True". The first time, the button is clicked, it causes a postback, but the image buttons .click event is not fired. For each subsequent click, the postback gets called, then the image buttons .click event is fired as expected. I have done this simple task numerous times, so I'm a little stumped. I've troubleshot everything I can think of (including cross referencing all the properties of both the page and control against working production examples). Here's the handler for my button. Thanks fo...

How to fire events in other web form from other web form ?
Suppose that I have A and B web form. I want to trigger B web form's Page_Load event from A web form. How can I do that ? Thanks in advanced WilbertWilbert Bujn Create a public method in B that call the load method : public void Load(object sender, System.EventArgs e) { Page_Load(sender, e) ; } In the page_load of A, instanciate a B object and then call the function B myB = new B() ; myB.Load() ; Quicky Thank you quicky, it works fine. WilbertWilbert Bujn...

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 = new Label();lblHeading.Font.Bold = true;lblHeading.Text = sqlData.GetValue(0).ToString()+"<br/>";News.Controls.Add(lblHeading);btnDelete = new Button();btnDelete.ID = sqlData.GetValue(1).ToString();btnDelete.Style.Add("float", "right");btnDelete.Text = "Delete";btnDelete.Click += new EventHandler(btnDelete_Click);News.Controls.Add(btnDelete);}sqlData.Close();Can someone let me know what is the problem?How i can overcome that problem. Thanks in Advance.  in order for dynamically created controls to raise events, they must be re-added to the page on all subsequent postbacks by page_load at the latest. FAQ: Banavige~~~~~~~~~~~~Need a site code sample in a different language? Try converting it with: You have to add the control on each postback with same ID. The ID...

button click event from another button click not firing
 Hi,  I want to trigger a button click event from another button click .It is not firing.  Please help.  protected void btnReview_Click(object sender, EventArgs e) {       if (MandatoryValidation())        {         this.Button1.Click += new System.EventHandler(this.Button1_Click);       } }protected void Button1_Click(object sender, EventArgs e) { } protected void btnReview_Click(object sender, EventArgs e){            if (MandatoryValidation())     {        this.Button1.Click += new System.EventHandler(this.Button1_Click); //The event is registered not called.        Button1_Click(null, null);      } }protected void Button1_Click(object sender, EventArgs e) { }Hope that helps  Techie (.Net Knowledge at its Best)We make a living by what we get, but we make a life by what we give.::: Winston Churchill :::  protected void btnReview_Click(object sender, EventArgs e) {       if (MandatoryValidation())        {         Button1_Click(null,null);       } }protected void Button1_Click(object sender, EventArgs e) { }Kamran...

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

Dynamic Event not firing on button click.
I have a problem in calling a dynamically contructed event on a button click(which is also dynamic). I have an server side ASP.NET button when clicked generates two dynamic buttons, 'Yes' and 'No'. When clicked on one of these two buttons i need to call an dynamically contructed event which i am unable to call. Not sure what the problem is. Clicking on Yes must display 'Hello' and click on No must display 'Hi'. I have to call that event. Below is the code i have written. C# code: using System; using System.Data; using System.Configuration; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls;public partial class _Default : System.Web.UI.Page {protected void Page_Load(object sender, EventArgs e) {   }protected void btnNextYes_Click(object sender, EventArgs e) {Response.Write("Hello"); }protected void btnNextNo_Click(object sender, EventArgs e) {Response.Write("Hi"); }protected void Button1_Click(object sender, EventArgs e) { CreateControls(); }private void CreateControls() {Label lblNextQuestion = new Label(); //lblNextQuestion.ID = "lblNextQuestion";// +next; //lblNextQuestion.Text = question;Button btnNextYes = new Button(); btnNextYes.ID = "btnNextYes123";// +next;btnNextYes.Text = "Yes"; btnNextYes.Click += new EventHandler(btnN...

Dynamically loaded Web User Control .ascx button click event handler not called on second time click
I have an ascx control (that performs actions for an entity) being added dynamically to accordion panes, and then the panes are added to an ajax accordion control, so that the accordion can contain multiple panes with each pane containing one ascx control. The ascx control contains a delete button which removes the entity from the database. Once the entity is removed, I need to reflect this deletion in the parent page by removing the accordion pane from the accordion. To do this I created a delegate function and which is called from the parent page to rebind the accordion and hence not d...

when the user clicks the image button to show the calendar extender on my web form it submits the whole form instead of showing the calendar??
when the user clicks the image button to show the calendar extender on my web form it submits the whole form instead of just showing the calendar??  I have another button that submits the form. my calendar image button is acting like a submit button also instead of acting like a calendar popout button. Does anybody know how I can set an image button to not submit the form and cause my validations to render. I only want it to pop out the Ajax calendar for the specific textbox?   <ajaxToolkit:CalendarExtender runat="server" TargetControlID="txtDate" CssClass="calendar" Format="MMMM d, yyyy"> </ajaxToolkit:CalendarExtender> <table cellpadding="2" style="width: 392px; left: 46px; position: relative; top: 1px;"> <tr> <td align="left" style="width: 894px; height: 8px" valign="middle"> Date:</td> <td align="right" style="width: 79px; height: 8px" valign="middle"> &nbsp;</td> <td style="width: 113px; height: 8px" align="left"> <asp:TextBox ID="txtDate" runat="server" Width="175px"></asp:TextBox></td> <td alig...

Gridview Event : image button's row command fire second time when i do refresh or postback after clicking on imgdelete button immidiatly
 i am getting  imgDelete (image button) row command fire second time when i do refresh or postback after clicking on imgdelete button immidiatly, so how can i prevent(handle) it from firing second is a user control   fun.ascx.vb Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load                       If IsPostBack = False Then            FillGridView()        End If           End Sub   Protected Sub gMain_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles gMain.RowCommand        If e.CommandName = "deleterow" Then            If e.CommandArgument <> "" Then                Dim dt As DataTable = SQLHelper.ExecuteQuery("select strCreatedBy from TblFunquizdetail where ID='" & e.CommandArgument & "'")                If dt.Rows.Count > 0 Then            ...

I Want to create a tool box,toolbox contains image button and fileupload.These two buttons can be added at runtime(user can add any number of image button and fileupload button dynamically by click)
I Want to create a tool box,toolbox contains image button and fileupload buttons.These two buttons can be added at runtime(user can add any number of image button and fileupload button dynamically by click).for every image user will browse images using fileuploader and he will add the image to that imagebutton at runtime. how to write server side coding to upload the selected image and to set that image to imagebutton at runtime? is it possible? any other way to do it?  advance thanks ask123: I Want to create a tool box,toolbox contains image button and fileupload b...

button click event not firing on dynamic usercontrol
Hi, I have a page that adds a user control dynamically (in the code behind).This usercontrol contains a small form and two buttons: save and cancel When opening the aspx page the usercontrol displays perfect, but when I click the save (or cancel) button nothing happens. It does a postback but it doesn't fire the onclick handler of the button clicked.When I set debug points in the onload and onclick handlers, only the onload event is hit when dynamically loading the usercontrol in the page.When clicking the save or cancel button no debug points are hit.When I create a test page and add ...

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

Image button click or Command events do not fires
Hi, I have a web user control that`s have a calendar control with the filtered dates in the DayRender event, I set the selectedDate to a especific value, the problem is:I fill a gridview control with a date tha I pass like select parameter, the thing is: A image button placed into the gridview column template doe´s not fires the command and/or the click event, only on the postback phase the DayRender is prossesed but the clic or Commannd no, and then selecting the date in the calendar magicly the imagebutton's click envent is fired. Wath's´Up? any sugestion, I`have fix this puti...

Hide image with button click in web form
I have around three tables in a web form and each tabl has one image each. I have a button just next to Image. This button when clicked will either Hide the image or Show the message...I'm not sure, why this is not working in a Web Form? It works in HTML page....Here is the sample code for JavaScript that i use and also the HTML script for the table and button... function ShowSearchImage() { var visible =; if ( visible == "" ) { = "none"; btnShowSearch.value = "Show image"; } if ( visible == "none" )...

How to fire the button click event in web part?
If I created a button control programmatically in a web form, I would use   public Button btnSearch = new Button();protected override void CreateChildControls(){ Button1.Click += new System.EventHandler(this.Button1_Click); this.Controls.Add(Button1); } protected void Button1_Click(object sender, EventArgs e) { //code here. }It doesn't work in a web part. It bombed at this.Controls.Add(Button1); after I clicked the button. How does the button click event get fire in web part? Thanks.DY  Im a bit confused here.. can you elaborate more? What really is your re...

SortCommand event is not getting fired after clicking Image Button
Hi, I am working on DataGrid sorting functionality. I added one template column in which Image Button is provided to Header Template. Code is like as follows <HeaderTemplate> '> <asp:ImageButton id="ImageButton1" runat="server" Width="15px" ImageUrl="IMAGES/ArrowSort.ico" CommandName="sort" CommandArgument="PrivilegeName"> </asp:ImageButton> '></Headertemplate> '>I am not able to execute SortCommand event. After clicking on Image Button '>Same functionality is working with only Link Button instead of Image Button. Normal button is also not able to execute S...

Multiple Button controls on form not firing Click event
There is probably a better way to do this, but here is what is going on. Imagine two "div" sections that contain images that have been tiled. One div contains all of the images that belong to a product, the other div contains the library of images you may want to assign to the product. Under each image in the library section is a Button control "Add". Under each image in the "Assigned to product" div there is a "Remove" Button control to remove it from the product. I'm trying to provide functionality where the user can simply click "Add&q...

how to fire a image button click event using javascript
hi, I have a image button inside the updatePanel, and I want click it using javascript. I tried some solution, but the click() event doesn't work: <script type="text/javascript"> function submit(){var imgButton=document.getElementById("<%=IBSubmit.ClientID%>");; //doesn't work } </script> could someone give a idea on this issue? It seems imagebutton kind of different from normal button. Thanks,Liya You can try using __doPostBack(imgButton, '');C# <---> VB.Net Translator  Could you explain it as wh...

Dynamically adding buttons to web form and wiring up the onclick event.
I have a web form that is generated at runtime with a number of dynamically created buttons. Creating the buttons is easy, but wiring them up is not. I would love to use the cold behind and a single onclick event. Then based on the id, I can call a single method that does an operation. Each button will perform the same tasks. The user can chose one of three tasks. I though I would either have a dropdown or three radio buttons for this. Alternatively, I could have some javascript, but I am not quiet sure how to post back with javascript and if all the buttons will make it more difficult. Does...

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

On enter
 I'm using .net 1.1. My content page is inside a template. There is a submit button in the template and in my page. When the user presses enter key, the button click event in the template page is firing. How do I force my button click event to fire on enter? I googled it and found a fix that if I add an input control it should fix it. But it didn't. Are there any other solutions? Here is my page's code. i don't have the template code.<form runat="server" id="FormDonor" method="post">          &nb...

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

Web resources about - Click event not fired for dynamic image button -

Dynamics - Wikipedia, the free encyclopedia
Brownian dynamics , the occurrence of Langevin dynamics in the motion of particles in solution (e.g. a grain in water, as was first seen by Brown); ...

Datacenter Dynamics
Datacenterdynamics for data center information, conferences, news, videos, whitepapers and reports globally

Dynamic Chiropractic - chiropractic, news, articles, research & information for chiropractors - Find ...
Dynamic Chiropractic - chiropractic, news, articles, research & information for chiropractors - Find a Chiropractor

Edelman Invests in Employee Advocacy Platform Dynamic Signal
Edelman has made a strategic investment in employee-advocacy and engagement platform Dynamic Signal, a move meant to help the agency's PR clients ...

How Dynamic Ads Can Supercharge Your SEM Campaigns #SMX
How Dynamic Ads Can Supercharge Your SEM Campaigns #SMX was originally published on, home of expert search engine optimization ...

Microsoft's new Dynamics ERP suite is on Azure
Microsoft has released the next version of its Dynamics AX enterprise resource planning software, giving companies a path to running more of ...

Master & Dynamic's brass earbuds mix style with great sound
So far, I haven't had the best luck with the earbuds I've reviewed: The OnePlus Icons were unremarkable, and though Earin sold me on the idea ...

Dynamics CRM Online Spring Update Integrates FieldOne, Adxstudio
The upcoming "spring wave" update to Microsoft's Dynamics CRM will add field service capabilities from FieldOne and online customer engagement ...

New dynamic Steam bundles give you credit for games you already own
A better deal is coming to a Steam bundle near you.

The Fluid Flow Dynamics Behind The Gravity Defying Bubbles In Guinness
... a pint of Guinness, you may have noticed that the bubbles in the glass travel downwards. How can they do this? It is all in the fluid dynamics ...

Resources last updated: 3/9/2016 10:49:39 AM