Reputation: 871
I am working with asp.net and i have some question here, any help will be great.I am trying to generate controls from Codebehind(C#) since the amount of data which is returned from server is uncertain, now my question is, is it possible to generate jquery datepicker control from C#? how to do that? show me some examples.
thank you.
Upvotes: 1
Views: 1403
Reputation: 2000
Try this..
Codebehind:
TextBox txt = new TextBox();
txt.ID = "datepicker";
div1.Controls.Add(txt);
If u want for more number of textboxes u can use cssclass instead of id.
TextBox txt = new TextBox();
txt.cssclass = "date";
div1.Controls.Add(txt);
Aspx:
<script type="text/javascript">
$(function () {
$("#datepicker").datepicker();//or $(".date").datepicker(); for more number of textboxes
});
</script>
Add required scripts and styles in aspx as well.To know more see this link.
Upvotes: 0
Reputation: 4550
Yes it is possible . You can have a common class which you want to use for Date Picker while creating your control add the class on the textbox on the server side.
txt.Attributes.Add("class", "myCal");
On the client side call this javascript
$(doucment).ready(function(){
$(".myCal").datepicker();
});
This will loop through all the textboxes with myCal as class and will it make it into datePicker
Upvotes: 3
Reputation: 434
you may check here to learn and see the sample codes of datepickers. I hope it works for you.
Upvotes: 0