I have an ASP.NET application in which I create a table dynamically. Each row in the table has columns for 5 days with a dropdown and a text box for each day - the idea is to record the number of hours worked by employees each day.
The drop down list has values for 'Attended', 'Holiday', 'Sick' etc and has an event handler associated with it to trap client side when the selection is changed.
My problem is that the table is within a parent tab control and as such the names get decorated. For example,
TableCell statusCell = new TableCell();
ddlStatus = new DropDownList();
ddlStatus.ID = table.ID + "_row_" + table.Rows.Count.ToString() + "_" + day + "_Status_" + lblWeekNumber.Text;
ddlStatus.EnableViewState = false;
ddlStatus.AutoPostBack = true;
ddlStatus.SelectedIndex = (timesheet == null) ? 0 : (int)timesheet.Status;
This adds a new cell to the table and adds a drop down to the cell. I then create the event handler currently as :-
ddlStatus.Attributes.Add("onchange", "EnableHours(ctl00$ContentPlaceHolder1$WebTab1$tmpl0$" + ddlStatus.ID
+ ", ctl00$ContentPlaceHolder1$WebTab1$tmpl0$" + tbHours.ID
Note that I hard-wire the 'prefix' for the drop down as if I simply add its ID this will not match up at runtime. I don't like this however as it relies on the hardcoded bit not changing - which it has in the past.
The event itself is declared quite simply as :-
function EnableHours(ddl, tbHours)
var statusID = ddl.options[ddl.selectedIndex].value;
I had hoped to be able to use the '<%=ddl.ClientID %>' type approach but have not been able to get this to work. Any suggestions to get around hard-wiring the prefix?