H
Henke
Hi,
Consider this code (simplified) example:
public class Person : Microsoft.SharePoint.WebPartPages.WebPart
{
private ImageButton _action = new ImageButton();
protected override void CreateChildControls()
{
this.Controls.Add(_action);
_action.Click +=new ImageClickEventHandler(action_Click);
}
protected override void RenderWebPart(HtmlTextWriter w)
{
Table tbl = new Table();
TableRow row = new TableRow();
TableCell cell = new TableCell();
cell.Controls.Add(_action);
row.Cells.Add(cell);
tbl.Rows.Add(row);
tbl.RenderControl(w)
}
}
When the above code is used the action_Click() event is not triggered
because I move the "_action" object in the controls collection tree from
this.Controls to cell.Controls. So instead of using the Table, TableRow and
TableCell objects for creating HTML I will have to use the code below
to render the HTML and hook up the _action OnClick event correctly.
protected overrid void RenderWebPart(HtmlTextWriter w)
{
w.Write("<table>");
w.Write("<tr>");
w.Write("<td>");
_action.RenderControl(w);
w.Write("</td>");
w.Write("</tr>");
w.Write("</table>");
}
Can this be solved by some other approach when working with custom controls?
Regards,
// Henke
Consider this code (simplified) example:
public class Person : Microsoft.SharePoint.WebPartPages.WebPart
{
private ImageButton _action = new ImageButton();
protected override void CreateChildControls()
{
this.Controls.Add(_action);
_action.Click +=new ImageClickEventHandler(action_Click);
}
protected override void RenderWebPart(HtmlTextWriter w)
{
Table tbl = new Table();
TableRow row = new TableRow();
TableCell cell = new TableCell();
cell.Controls.Add(_action);
row.Cells.Add(cell);
tbl.Rows.Add(row);
tbl.RenderControl(w)
}
}
When the above code is used the action_Click() event is not triggered
because I move the "_action" object in the controls collection tree from
this.Controls to cell.Controls. So instead of using the Table, TableRow and
TableCell objects for creating HTML I will have to use the code below
to render the HTML and hook up the _action OnClick event correctly.
protected overrid void RenderWebPart(HtmlTextWriter w)
{
w.Write("<table>");
w.Write("<tr>");
w.Write("<td>");
_action.RenderControl(w);
w.Write("</td>");
w.Write("</tr>");
w.Write("</table>");
}
Can this be solved by some other approach when working with custom controls?
Regards,
// Henke