![]() |
|
|
|||||||
![]() |
ASP Net - Custom Usercontrol; Event not triggered |
|
|
Thread Tools | Search this Thread |
|
|
#1 |
|
Hi all,
I have a Usercontrol containing a pre-formatted DataGrid and some code which by default enables paging (with links 1..20). I now want to add some extra paging information to the PagerTemplate using the code below. It does show me all the labels and links, but the event I attach to the previous and next links isn't triggered on click. I must be doing something wrong, perhaps you can help me out? TIA --- the code (hope it's readable) --- private void grid_ItemCreated(object sender, DataGridItemEventArgs e) { if (e.Item.ItemType == ListItemType.Pager) { // Extract the Pager TableCell pager = (TableCell)e.Item.Controls[0]; //Add Cell to Row to Hold Row Count Label TableCell newcell = new TableCell(); newcell.ColumnSpan = this.grid.Columns.Count / 2; newcell.HorizontalAlign = HorizontalAlign.Left; newcell.ID = "pagerInfo"; //Add Table Cell to Pager e.Item.Controls.AddAt(0, newcell); //Subtract from Colspan of Original Pager to Account for New Row pager.ColumnSpan = pager.ColumnSpan - 1; } } private void grid_PreRender(object sender, EventArgs e) { try { // add pagerinfo to top and bottom pagertemplate this.GridPagingInfo(((TableCell)grid.Controls[0].Controls[0].FindControl("pagerInfo"))); this.GridPagingInfo(((TableCell)grid.Controls[0].Controls[grid.Controls[0].Controls.Count - 1].FindControl("pagerInfo"))); } catch {} } private void GridPagingInfo(TableCell p) { if (this.RecordCount > 0) { Label pageInfo = new Label(); /* paging info */ pageInfo.Text = this.RecordCount.ToString() + " records "; pageInfo.Text += "| " + this.grid.Items.Count.ToString() + " shown | " + "Page " + (this.grid.CurrentPageIndex + 1).ToString() + " of " + Math.Ceiling(Convert.ToDouble(this.RecordCount)/this.grid.PageSize); p.Controls.Add(pageInfo); p.Controls.Add(new Seperator()); // previous-button if (this.grid.CurrentPageIndex > 0) { LinkButton gridPreviousLink = new LinkButton(); gridPreviousLink.Text = "Previous"; p.Controls.Add(gridPreviousLink); gridPreviousLink.Click += new EventHandler(gridPreviousLink_Click); } else { Label gridPreviousLabel = new Label(); gridPreviousLabel.Text = "Previous"; gridPreviousLabel.ForeColor = System.Drawing.ColorTranslator.FromHtml("#999999") ; p.Controls.Add(gridPreviousLabel); } p.Controls.Add(new Seperator()); // next-button if ((this.grid.CurrentPageIndex ) < (this.RecordCount / this.PageSize)) { LinkButton gridNextLink = new LinkButton(); gridNextLink.Text = "Next"; p.Controls.Add(gridNextLink); gridNextLink.Click += new EventHandler(gridNextLink_Click); } else { Label gridNextLabel = new Label(); gridNextLabel.Text = "Next"; gridNextLabel.ForeColor = System.Drawing.ColorTranslator.FromHtml("#999999") ; p.Controls.Add(gridNextLabel); } } } Sjaakie |
|
|
|
|
#2 |
|
Junior Member
Join Date: Aug 2006
Posts: 1
|
Hi,
When I need to have a usercontrol fire events I create a class that inherits from control, usercontrol or webcontrol and define the event XXX and an OnXXX function to allow derived classes to raise the event. Then rather than the usercontrol inheriting from usercontrol, it inherits from my class with the event. Hope this helps. Paul Manalishi |
|
|
|
![]() |
| Thread Tools | Search this Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Asp.Net Custom Controls & Safari Compatibility | Osiris | General Help Related Topics | 0 | 06-01-2009 08:03 PM |
| Event Viewer question | bootmgr | MCITP | 0 | 10-10-2008 02:22 PM |
| RIP HD-DVD? - HD-DVD CES Event Canceled | Air Raid | DVD Video | 0 | 01-05-2008 03:06 AM |
| How do find out if a button was clicked before the textchanged event of textbox fires | Jack | General Help Related Topics | 0 | 10-27-2006 10:19 AM |
| SUPER BOWL GALA EVENT, tickets available | TheLeiterSideYGB | DVD Video | 1 | 01-06-2004 11:55 PM |