Problem deriving from WebControl Class

G

Gary Rynearson

I have an aspx form that conatains a WebControls.Table object. I also have
a class inheriting from the WebControl class. That class is instantiated
using the Table as a parameter, and adds checkboxes into rows / cells, as
shown in the code below.

The page loads fine, but after a postback, the checkboxes do not appear.

Can anyone provide assistance on getting them to persist?

Gary

public class RolesCheckBoxes : System.Web.UI.WebControls.WebControl

{

ImportContacts.BSTRoles _bstRoles = null;

Table _tbl;

string _test = string.Empty;

public RolesCheckBoxes( ImportContacts.BSTRoles bstRoles, Table tbl )

{

_bstRoles = bstRoles;

_tbl = tbl;

}

protected override void CreateChildControls()

{

Table tbl = _tbl;

TableRow row = new TableRow();

TableCell cell = new TableCell();

HyperLink a = new HyperLink ();

CheckBox ckBx = new CheckBox();

foreach (DataRow currRow in _bstRoles.Roles.Tables[0].Rows)

{

row = new TableRow();

cell = new TableCell();

ckBx = new CheckBox();

ckBx.Text = currRow["Name"].ToString ();

ckBx.ID = currRow["Code"].ToString ();

cell.Controls.Add (ckBx);

row.Cells.Add (cell);

tbl.Rows.Add (row);

}

tbl.BorderWidth = 1;

tbl.BorderStyle = BorderStyle.Ridge;

}

}

}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,576
Members
45,054
Latest member
LucyCarper

Latest Threads

Top