views:

22

answers:

1

Hi, I have deployed asp.net mvc 2 application successfully. but let say there is view fro create user where I used code for datetime picker :

<script type="text/javascript">
    $(function() {
    $('#DateOfBirth').datepicker({ dateFormat: 'dd/MM/yy',
            changeMonth: true,
            changeYear: true
        });

    });

    </script>

This is working fine. But same code I used on Edit view for the user . but not working . why should not this ?
Edit View script for datetimepicker is :

<script type="text/javascript">
    $(function() {
    $('#DateOfBirth').datepicker({ dateFormat: 'dd/MM/yy',
            changeMonth: true,
            changeYear: true
        });

    });

    </script>
+1  A: 

If you are editing on the same page, try using a class instead of id for the element under question:

$(function() {
$('.DateOfBirth').datepicker({ dateFormat: 'dd/MM/yy',
        changeMonth: true,
        changeYear: true
    });
});

You need to give the element attribute of class:

<.... class="DateOfBirth"
Sarfraz
where have to give this element ?
Lalit
@Lalit: The element you have assigned the id to `DateOfBirth`. Replace `id` with `class`.
Sarfraz
Sorry to ask this, but I have code like this :<div class="editor-field float-left"> <%= Html.TextBox("DateOfBirth", Model.DateOfBirth.ToString("dd/mm/yyyy"), new { @class = "wide" })%> <%= Html.ValidationMessageFor(model => model.NextElectionDate)%> </div> so i am in confusion. out of this what i have to give there?
Lalit