I have a custom usercontrol, which is basically a dropdownlist, prepopulated with values from the database.
<asp:DropDownList ID="selResponseTimes" runat="server" SkinID="filterSkin">
</asp:DropDownList>
Code behind:
public partial class Response_Times_Drop_Down : System.Web.UI.UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
DataTable objDataTable = DAL.ExecuteDataTable("sp_cl_Response_Times_Get", null);
selResponseTimes.DataSource = objDataTable;
selResponseTimes.DataTextField = "TM_Code";
selResponseTimes.DataValueField = "TM_Code";
selResponseTimes.DataBind();
}
}
public string SelectedValue
{
get
{
return selResponseTimes.SelectedValue;
}
set
{
selResponseTimes.SelectedValue = value;
}
}
}
The control is added to my page as follows, and works fine:
<asp:ResponseTimesDropDown runat="server" ID="selResponse" />
I’m adding client side events as attributes to standard controls on Page_Load using the following:
txtCallRelatedCall.Attributes.Add("onblur", "CheckRelatedCall()");
However, when I attempt to do this with my custom control they are not being added.
selResponse.Attributes.Add("onchange", "CalculateResponseTime()");
However if I debug the code, the attributes are being added to the collection, it appears that they are just not being output to the page. Why is this?
In what stage of the page lifecycle are you adding the attributes?
Try adding them in on
Page_InitEDIT (See Comments):
Then in the from you can call CalculateResponseEnabled by doing.