Last post Nov 18, 2007 10:34 PM by Nai-Dong Jin - MSFT
Nov 15, 2007 03:43 AM|bo2bo2|LINK
i am creating a webcontrol in a webcontrol library
in the constructor of the control i have created all the controls i need and i have one of these controls as a datagrid which calls a few methods and then i call its DataBind()
i have two events attached to it itemdatabound
and the other is itemcommand which neverfires as everytime the page containing the control always calls the databind of the control....
Nov 15, 2007 05:15 AM|Brent Jenkins|LINK
Nov 15, 2007 05:28 AM|bo2bo2|LINK
[:)] nice but no, webcontrol class which i inherit doesn't seem to have this it has parent and page though which are null
Nov 15, 2007 05:38 AM|Brent Jenkins|LINK
If it's a Web User Control inherited from the base class System.Web.UI.UserControl then it has a Page_Load() method which you can override and use the Page.IsPostBack property.
If, on the other hand, you are inheriting from System.Web.UI.WebControls then you can use Page.IsPostBack by overriding the OnLoad() method.
Nov 15, 2007 06:57 AM|bo2bo2|LINK
if i put populate() in onload overrides nothing ever gets rendered [:)]
internal class ConfigurationEnumeration : WebControl
protected override void OnLoad(EventArgs e)
Panel container =new Panel();
DataGrid grid =new DataGrid();
public delegate void ValueSelectedEventHandler(object source, string valueSelected);
public event ValueSelectedEventHandler ValueSelected;
private void populate()
grid.ItemDataBound += new DataGridItemEventHandler(DataGrid_ItemDataBound);
grid.DataSource = someData;
private void DataGrid_ItemDataBound(object sender, DataGridItemEventArgs e)
if (e.Item.DataItem != null)
Button link = new Button();
link.Click += new EventHandler(link_Click);
link.Text = e.Item.Cells.Text;
link.CommandName = "select";
link.CommandArgument = e.Item.Cells.Text;
e.Item.Cells.Text = string.Empty;
private void link_Click(object sender, EventArgs e)
// now this never fires
if (ValueSelected != null) ValueSelected(this, ((Button)sender).CommandArgument.ToString());
protected override void RenderContents(HtmlTextWriter output)
i hope this explains my problem
Nov 16, 2007 10:26 AM|bo2bo2|LINK
Nov 18, 2007 10:34 PM|Nai-Dong Jin - MSFT|LINK
From your description, it seems that you want to create a DataGrid control in your custom server control, bind a datasource to the control and add it to the page’s control set, right?
Based on your code, you have make those work like creating the DataGrid control, binding the datasource, adding to the pages in the constructor of the custom control class. But generally, they should be finished by overriding CreateChildControls() method.
I suggest that you may refer the following guide on how to create child control in custom server control: (Following the samples inside.)