Go Back   Velocity Reviews > Newsgroups > ASP Net
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply

ASP Net - Custom Usercontrol; Event not triggered

 
Thread Tools Search this Thread
Old 07-19-2006, 09:55 AM   #1
Default Custom Usercontrol; Event not triggered


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
  Reply With Quote
Old 08-06-2006, 10:49 PM   #2
Manalishi
Junior Member
 
Join Date: Aug 2006
Posts: 1
Default
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
Manalishi is offline   Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

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




SEO by vBSEO 3.3.2 ©2009, Crawlability, Inc.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46