Click here to Skip to main content
15,885,988 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Im trying to use javaScript datepicker on ASP.NET, Visual Studio 2010.
I cant associate it on a Server Component.

<script type="text/javascript">
        $(function () {
            $('#BTTDataFIM').datepicker({
                dateFormat: 'dd/mm/yy',
                changeMonth: true,
                dayNamesMin: ['Sg', 'Tr', 'Qa', 'Qi', 'Sx', 'Sb', 'Dm'],
                dayNamesShort: ['Seg', 'Ter', 'Qua', 'Qui', 'Sex', 'Sab', 'Dom'],
                defaultDate: null,
                nextText: 'Próximo',
                prevText: 'Anterior',
                showAnim: 'fold',
                showOn: 'button',
                buttonText: '...'
            });
        });
        }
    </script>

    <input type= "text" id="BTTDataFIM" class="CampoData" value="" />

It works properly, but I need a Server Control (INPUT) Component, to read the selected Date by the C# code.
If I Change my INPUT component to a runat="Server" object, the datepick component stops to work.

Can anybody help me ?

Thanks.

Guilherme
Posted
Updated 2-Apr-12 9:18am
v2
Comments
[no name] 2-Apr-12 15:18pm    
Format code snippets
Dean Oliver 3-Apr-12 1:02am    
ASP.NET MVC or ASP.NET?

It is most likely an issue with the name mangling applied by ASP.NET when elements are rendered. id="BTTDataFIM" will be changed to something like id="ctr001_BTTDataFIM".

You can work around this by using

$("[id$='BTTDataFIM']")


which will find the element with an ID that ends with BTTDataFIM, regardless of what prefixes are applied.
 
Share this answer
 
Comments
Dean Oliver 2-Apr-12 16:02pm    
This line of code is correct $('#BTTDataFIM'). The problem does not lie in referencing the datepicker to the control. The problem is with the binding in c#. asp.net won't automatically rename the id like this id="ctr001_BTTDataFIM" as well .
[no name] 2-Apr-12 16:21pm    
"asp.net won't automatically rename the id like this id="ctr001_BTTDataFIM" as well" When using runat=server it will. You should review ASP.NET rendering rules.

Are you using ASP.NET or MVC?
Dean Oliver 3-Apr-12 1:02am    
read the question ""If" I Change my INPUT component to a runat="Server" object". It's not running with runat="server."
[no name] 3-Apr-12 7:08am    
Yes, Read the question "If I Change my INPUT component to a runat="Server" object, the datepick component stops to work."

Notice the part about it STOPS working AFTER runat=server is applied?

Think before you respond next time.
Firstly it sounds like you using ASP.NET MVC the reason why the value is not being bound to your c# code. is one you not submitting the form and two your controller needs to have a method of type actionresult with a parameter as the same name as your input control.
eg;

C#
public ActionResult SaveDate(DateTime BTTDataFIM)
{
  //logic etc
}


http://stackoverflow.com/questions/5341917/asp-net-mvc-3-model-binding-and-form-fields[^]

http://blogs.msdn.com/b/aspnetue/archive/2010/09/17/second_2d00_post.aspx[^]

http://msdn.microsoft.com/en-us/library/dd410405.aspx[^]

http://msdn.microsoft.com/en-us/library/gg416514%28v=vs.98%29.aspx[^]
 
Share this answer
 
Comments
[no name] 2-Apr-12 16:21pm    
"Firstly it sounds like you using ASP.NET MVC"
Where do you get this assumption from?
Dean Oliver 3-Apr-12 1:04am    
"to read the selected Date by the C# code." In the question, look it is an assumption because the technology he's using hasn't been openly specified.

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