Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Good afternoon all. I have a question that I think has a simple answer and I just can't figure it out.

I have a form that the user fills out in which the data gets inserted into a SQL database. One example of a text box I'm using in the form is this:

<asp:TextBox ID="NameOfAgencyTextBox" runat="server" Text='<%# Bind("NameOfAgency") %>' Width="248px" />


I've recently discovered JQuery and found a really nice date/time picker that I've implemented into the form as so:

<script>
  $(function() {
    $( "#datepicker" ).datepicker();
  });
  </script>


ASP Markup
<input type="text" id="datepicker">


Obviously the picker works but it is supposed to be inserted into the field "DateOfIncident". If I construct my binding inside the input the application breaks ie:

<input type="text" id="datepicker" Text='<%# Bind("DateOfIncident") %>


Please can someone help me? Also, let me know if I need to clarify anything.
Posted
Updated 14-May-14 10:31am
v2
Comments
j snooze 14-May-14 17:15pm    
what is the error? Define "the application breaks".
Also curious as to why you aren't using an asp:Textbox for the date? Perhaps if you do that and bind to the serverside field instead of using an html element it will work? Just make the id of the textbox datepicker.

 
Share this answer
 
try with CssClass
C#
<asp:TextBox ID="NameOfAgencyTextBox" runat="server" Text='<%# Bind("NameOfAgency") %>' Width="248px" CssClass ="date" />

then you can use class selector in your jquery
JavaScript
<script>
  $(function() {
    $( ".date" ).datepicker();
  });
</script>
 
Share this answer
 
v3
Comments
Branden Coker 15-May-14 8:30am    
Thank you very much for your responses.

j snooze, this is the error I'm receiving:

0x800a01b6 - JavaScript runtime error: Object doesn't support property or method 'datepick'

I'll read the text you've supplied Peter.

I'll also look into your code as well DamithSL. Thanks a bunch guys as always it's a pleasure learning from the community. Cheers!
Branden Coker 15-May-14 10:12am    
If I may ask, what is the
<pre>xmlns:asp="#unkown"</pre> for?

I'm getting the message "error creating control, server tag is not well formed."
DamithSL 15-May-14 11:04am    
please remove that, it was added automatically when the code formating in this codeproject answer input area.
Branden Coker 16-May-14 12:11pm    
This is what I've changed the code to:
<asp:textbox id="Textbox1" runat="server" text="<%# Bind("NameOfAgency") %>" width="248px" class="date" />

For some reason, it still says, "Error creating control, the server tag is not well formed" and there is a blue line under the entire string. Any ideas? I also copied the Script into my code as instructed. There is no problem with the script at the moment.
DamithSL 16-May-14 22:52pm    
please change class="date" to CssClass ="date"

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900