473,795 Members | 3,439 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Event not firing on a runtime-addedd control

Hi,

I have a problem in my C# web project: I have extended the GridView
class to add some sorting features. Additionally, I need to add a
quick-filter table at the bottom of this control, that will allow me to
implement this feature in all my grids.
I thought to simply add a table in the gridview OnPreRender event, with
soem cells and 1 link on each cell, but the Click event attached on the
links never fires... here's my code:

---------------
public class MyGridView : GridView
{
private int footerRowIndex = 0;
private Table filterTable;

public MyGridView()
{
}

protected override void OnRowCreated(Gr idViewRowEventA rgs e)
{
base.OnRowCreat ed(e);

if (e.Row.RowType == DataControlRowT ype.Footer)
{
filterTable = MakeAlphabetTab le();
}
else ++footerRowInde x;
}
protected override void OnPreRender(Eve ntArgs e)
{
base.OnPreRende r(e);

Table tbl = this.FooterRow. Parent as Table;
if (tbl != null) CreateFooterRow (tbl, footerRowIndex + 1);
}
private void CreateFooterRow (Table tbl, int index)
{
GridViewRow row = new GridViewRow(-1, -1,
DataControlRowT ype.Footer, DataControlRowS tate.Normal);
TableCell cell = new TableCell();
cell.Controls.A dd(filterTable) ;
cell.ColumnSpan = this.Columns.Co unt;
row.Cells.Add(c ell);
row.ID = "AlphabeticalFi lter_" + i;
tbl.Rows.AddAt( index, row);
}
private Table MakeAlphabetTab le()
{
Table item = new Table();
TableRow row = new TableRow();

for (char i = char.Parse("A") ; i <= char.Parse("Z") ; i++)
{
TableCell cell = new TableCell();
LinkButton btn = new LinkButton();

btn.Text = ((char)i).ToStr ing().ToLower() ;
btn.Click += new EventHandler(On Filtering);

cell.Controls.A dd(btn);
row.Controls.Ad d(cell);
}
item.Controls.A dd(row);

return item;
}
protected virtual void OnFiltered()
{
}
void OnFiltering(obj ect sender, EventArgs e)
{
//do something
}
}
---------------

My problem is that the function OnFiltering will never be called on this
code.

Can someone please help me understanding what happens?

Thank you!
Jul 29 '08 #1
2 1416
if you add any control by code you need to add it again in postback,
also make sure of use an unique Id as the control's ID
Jul 29 '08 #2
Ignacio Machin ( .NET/ C# MVP ) ha scritto:
if you add any control by code you need to add it again in postback,
also make sure of use an unique Id as the control's ID
Hi Ignacio,

I have done all of this, but the click event is not firing again...

Thank you
Jul 30 '08 #3

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

Similar topics

13
7499
by: Manuel Lopez | last post by:
I have a puzzling form timer problem that I didn't experience prior to Access 2003 (though I'm not sure access 2003 is to blame). Here's the situation: a computer has two access 2003 databases on it, a frontend and a backend. Case 1: If vba code on the frontend updates many rows (360,000) on the backend, a form's timer event (from the frontend) will stop firing until the user gives the form focus. (Note that the update itself always...
4
7428
by: Sampriti | last post by:
I am trying to delete a file from a disk when the user's session ends. So I am putting my file.delete code in Session_End event. I ran the application in the debug mode. When the session timesout session event is firing but it is not executing any of my delete code. Can somebody tell me what I am doing wrong? Thanks in advance
0
1694
by: Ram | last post by:
I have a start page for my application default.htm which contains four frames. header.htm login.aspx rightside.htm footer.htm login.aspx conatins username, password fields and login button. When the login is successful login page writes back javascript
5
4934
by: Engineerik | last post by:
I have a login form which I want to display with the showdialog method. When I do that the event handler for the load event does not run. If I use the show method the load event handler runs perfectly. I can't find any documentation regarding the load event not firing when a form is displayed using the showdialog method.
5
1843
by: Datagridtextboxcolumn not firing event | last post by:
"PLEASE HELP, I NEED HELP N O W !!!" AddHandler dgtxtboxcolumn.textbox.KeyDown, AddressOf TextBoxKeyPress Private Sub TextBoxKeyPress(ByVal sender as Object, ByVal e as KeyEventArgs) End Sub Not Firing the Enter Key event except Other Keys.
1
5063
by: Diana | last post by:
I've got a database that has been working successfully for a number of years now. I just added a new item - basically a field that becomes visible depending on another field's value. When I was testing this, I noticed that the OnCurrent event wasn't firing. I went to an older version of the program and saw that it wasn't firing there either. I don't know how long this has been going on, but it's quite distressing. To test the firing, I...
6
28176
by: Kevin Attard | last post by:
I am using a GridView inside a UserControl which has a template column for deleting the rows. Before databinding the gridview i am attaching the RowCommand and RowDataBound event. I am using the RowDataBound event to set the commandargument of the delete button. The event is being fired and works fine. When I press the delete button, the RowCommand event is not firing! and neither is the RowDeleting (the button's commandName is...
5
4546
by: jaysonnward | last post by:
Hello All: I've recently been recreating some 'dropdown menus' for a website I manage. I'm writing all my event handlers into my .js file. I've got the coding to work in Firefox, but the onmouseleave / onmouseout event I've attached to my hidden drop down (in this case an <ul>), is not firing correctly. It seems that when the mouse enters the ul it fires the mouseleave event. The problem is in the hideMenu2(e) function. I'm copying...
6
19272
by: sjoshi | last post by:
I have a derived class OraBackup which has a method that calls stored procedure on Oracledb to get status of backup job. Now the base class publishes an event like this: public delegate void PercentEventHandler(object sender, JobCompletedEventArgs e); public event PercentEventHandler PercentCompleted; And fires it:
1
2871
by: bigijoseph | last post by:
Please help : page load event is not firing. -------------------------------------------------------------------------------- Hi, I am a new to .net. I am trying to learn it. I tried the following code to execute. But the page load event is not firing. I tried , the same function rewriten in C#, then page load event worked absolutely fine. I dont know why the page load event is not firing in VB.net . Could some one try please try my same...
0
9672
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, 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...
0
9519
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10437
Oralloy
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...
0
10214
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 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...
0
10001
tracyyun
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...
1
7538
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5563
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3723
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2920
bsmnconsultancy
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.