473,396 Members | 1,812 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Event Handling dynamically

//I have the event declerations as follows down in a separate class file

public event CommandEventHandler PageNumberClicked;

//I have created link button dynamically using the following C# code which is also available in the same class
Expand|Select|Wrap|Line Numbers
  1.             HtmlTableCell htcPageNumber = new HtmlTableCell();
  2.             htcPageNumber.Attributes.Add("valign", "middle");
  3.             LinkButton lnkNewPageLink = new LinkButton();
  4.             lnkNewPageLink.EnableViewState = true;
  5.             lnkNewPageLink.ID = "Page" + (iCount + 1).ToString().Trim();
  6.             lnkNewPageLink.Text = (iCount + 1).ToString().Trim();
  7.             lnkNewPageLink.CommandName = (iCount + 1).ToString().Trim();
  8.             lnkNewPageLink.CommandArgument = (iCount * iRecordCount).ToString().Trim();
  9.             lnkNewPageLink.Command += new CommandEventHandler(PageNumberClicked);
  10.             lnkNewPageLink.CssClass = "pagerLink";
  11.             htcPageNumber.Controls.Add(lnkNewPageLink);
  12.             pagerInnerTable.Rows[0].Cells.Insert(iCount,htcPageNumber);
  13.  
  14.  
  15. //The above class has been instantiated in the user interface page
  16. //The event has been declared in the following way in the form load event
  17.  
  18.         if (!Page.IsPostBack)
  19.         {
  20.             StartIndex = 0;
  21.             objGrid.PageNumberClicked += new CommandEventHandler(lnkPage_Click);
  22.         }
  23.  
  24. //The event function is given below
  25.     void lnkPage_Click(object sender, CommandEventArgs e)
  26.     {
  27.         StartIndex = Int32.Parse(e.CommandArgument.ToString());
  28.         //BindData();
  29.         ManageGrid();
  30.     }
  31.  
  32. //The problem is the event is not getting fired when we actually click on the 
  33. //link button created dynamically.
  34.  
  35. //The link buttons will be created after loading the data into the grid. The page 
  36. //Number will be created dynamically,
Jun 27 '08 #1
1 1431
Frinavale
9,735 Expert Mod 8TB
Check out the article on how to use dynamic controls in asp.net. I think your problem is that your not instantiating your LinkButtons in your Page_Init event.

-Frinny
Jun 27 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Eric | last post by:
How can I dynamically assign an event to an element? I have tried : (myelement is a text input) document.getElementById('myelement').onKeyUp = "myfnc(param1,param2,param3)"; ...
10
by: b.dam | last post by:
I'm trying the following: function grid() { this._el = document.createElement("TABLE"); var self = this; document.addEventListener("onkeydown", function(event) {self.gridKeyDown(event);},...
0
by: luca | last post by:
Hi all. My problem is that I can't handle events raised from child components within a composite server control when the control is created dynamically. Everything works fine if the same control...
6
by: Steve Caliendo | last post by:
Hi, I'm creating 5 ImageButton controls in the panel control, and I have a unique ID specified for each one. When I click on any one of them, the Page_Load executes (Of course), but how do I...
9
by: Sridhar | last post by:
Hi, I have created a web page which includes a place holder. I also have a dropdown list in that webpage. when I select one of the choices in that dropdown list, It will load a user control...
15
by: Amit D.Shinde | last post by:
I am adding a new picturebox control at runtime on the form How can i create click event handler for this control Amit Shinde
9
by: Marcelo Cabrera | last post by:
Hi, I have a user control that in turn creates a bunch of webcontrols dynamically and handles the events these webcontrols raise. It used to work fine on ASP .Net 1.1 but when compiled on 2.0 it...
7
by: Ron Goral | last post by:
Hello I am new to creating objects in javascript, so please no flames about my coding style. =) I am trying to create an object that will represent a "div" element as a menu. I have written...
5
by: =?Utf-8?B?TWFyYyBXb29sZnNvbg==?= | last post by:
Hi, I have a strange issue occurring with LinkButtons that are dynamically added to each (data) row of my DataGrid on that grid's ItemDataBound event. Each LinkButton is assigned its own event...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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...
0
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...

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.