I tried all possible ways to add javascript code to my dynamically created control a date textbox but it is not working. I need to add multiple scripts like searchable dropdownlist and datepicker for date textbox. I am creating control on Page_Init and then attaching javascript on Page_Load but it is not working. Can somebody help, please? Thanks.
protected void Page_Init(object sender, EventArgs e)
{
CreateControls();
}
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
if (fieldtype == "date")
{
string javaScriptString = @"function attachJSScript() {";
javaScriptString += @"$('#<%= " + str + ".ClientID %>').datepicker({ dateFormat: 'dd/mm/yy' }).val();";
javaScriptString += @"}";
ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "attachJSScript", javaScriptString, true);
}
}
}
}
When I view the page source, it shows
<script type="text/javascript">
//<![CDATA[
function attachJSScript() {$('#<%= txt_1_date_yes.ClientID %>').datepicker({ dateFormat: 'dd/mm/yy' }).val();}//]]>
</script>
I added this code for dropdownlist dynamically created control but it is not working either. Same code I used for the controls in aspx pages and that works.

<%= .. %>) when writing the JavaScript string. As evident, they "don't work" (and are not needed) in that context. Instead, emit the control's actual ClientID so that it might look like$("#the_controls_client_id").datepicker..fieldTypecoming from? You could probably bind the date picker with$("[type=date]").datepicker()