I am new to jquery and I have a master page that has all the links to the basic jquery library files. In the aspx page I am creating multiple dynamic controls in the code behind page.
I have a link in the maincontent control for myjquery.js file that has the code to add a datepicker.
When my dynamic controls get built in code behind, they are not picking up the calendar from the file myjquery.js. Is that because these are dynamic controls?
In my code behind file where I create the controls. I am giving an Id to my text controls like this txtfield.Id = datepicker
SarahBenjami...
Member
256 Points
252 Posts
Jquery dynamic controls bind
Dec 19, 2012 12:11 AM|LINK
I am new to jquery and I have a master page that has all the links to the basic jquery library files. In the aspx page I am creating multiple dynamic controls in the code behind page.
I have a link in the maincontent control for myjquery.js file that has the code to add a datepicker.
When my dynamic controls get built in code behind, they are not picking up the calendar from the file myjquery.js. Is that because these are dynamic controls?
In my code behind file where I create the controls. I am giving an Id to my text controls like this txtfield.Id = datepicker
and then in myjquery.js I have teh code like this
(document).ready(function () { $('#datepicker').datepicker({ showOn: 'button', buttonImage: 'images/calendar.gif', buttonImageOnly: true }); });But nothing shows up on the page when its rendered.
geniusvishal
Star
14242 Points
2807 Posts
Re: Jquery dynamic controls bind
Dec 19, 2012 09:09 AM|LINK
Refer:
http://www.misfitgeek.com/2011/03/using-jquery-ui-datepicker-in-an-asp-net-application/
http://webdesignandsuch.com/add-a-calendar-date-picker-to-a-form-with-jquery/
My Website
www.dotnetvishal.com
manjuby
Participant
1131 Points
251 Posts
Re: Jquery dynamic controls bind
Dec 19, 2012 10:43 AM|LINK
Have u included AutoPostBack="true" ? ...also have ur document.ready like below..and go thru d example
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title></title>
<script type='text/javascript' src='http://code.jquery.com/jquery-1.4.2.js'></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.4/jquery-ui.js"></script>
<link rel="stylesheet" type="text/css" href="/css/normalize.css"/>
<link rel="stylesheet" type="text/css" href="/css/result-light.css"/>
<link rel="stylesheet" type="text/css" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.4/themes/smoothness/jquery-ui.css"/>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="txtPickupDate" runat="server" OnTextChanged="txtPickupDate_TextChanged" CssClass="datepicker" AutoPostBack="true"></asp:TextBox>
</div>
</form>
<script type="text/javascript">
$(document).ready(function() {
$(".datepicker").datepicker({
constrainInput: true,
dateFormat: 'dd D M yy'
});
});
</script>
</body>
</html>
And server side
protected void txtPickupDate_TextChanged(object sender, EventArgs e)
{
DateTime pickupDate = DateTime.Parse(txtPickupDate.Text);
}