0

Pretty simple, here is the js:

 <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6/jquery.min.js" type="text/javascript"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js" type="text/javascript"></script>
<link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css" rel="Stylesheet" type="text/css" />
<script type="text/javascript">
    $(function () {
        $("[id$=txt_Date]").datepicker({      
        });

    });

    //Set the default date today
    $(document).ready(function () {
        var currentDate = new Date();
        $("#txt_Date").datepicker("setDate", currentDate);
    });

</script>

Here is the control on the page. The page has a master page and in the content area the control is nested in an asp:Table, asp:TableRow, asp:TableCell structure.

<asp:TextBox ID="txt_Date" columns="30" runat="server" ReadOnly="true" name="RequestDate"></asp:TextBox>

Here is the code behind where I attempt to capture the value on a submit_click:

Date = Convert.ToDateTime(Request.Form["txt_Date"]);

I have also tried:

Date = Convert.ToDateTime(Request.Form["RequestDate"]);

Every attempt has returned 01/01/0001 as the date which I am guessing is just the default when it reads a NULL value from the control I am sure this is probably simple but I must be missing it.

2
  • Have you tried txt_Date.Value? Commented Aug 26, 2015 at 19:42
  • I have notice one thing you are adding datepicker to single control two times , you dont need this code $(function () { $("[id$=txt_Date]").datepicker({ }); Commented Aug 26, 2015 at 19:42

2 Answers 2

1

you can simply use:

Date = Convert.ToDateTime(txt_Date.Text);

I have noticed one more thing which is not required

 $(function () {
        $("[id$=txt_Date]").datepicker({      
        });    
    });

As you are already writing initialization & assignment in document ready event.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, I knew it was pretty simple, it is just a lack of experience at this point.
1

Because ReadOnly is set to true, Request.Form will not contain your data. You can either access the Text property as suggested in another answer, or you can remove the ReadOnly attribute, which I think is the better option. It's generally best to handle user input through validation instead of attempting to restrict said input (I remember the days when everyone thought it was a good idea to disable the back button).

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.