1

Is there a work around to get the value of the textbox? Let's say I set the textbox datepicker to 09-14-2014 then after clicking button it returns no value.

Here's my code:

<script type="text/javascript">
        $(function () {
            $("[id$=txtDate1]").datepicker({
                dateFormat: 'mm-dd-yy',
                showOn: 'button',
                buttonImageOnly: true,
                buttonImage: 'Images/calendar.png'
            });
        });
    </script>

<asp:TextBox ID="txtDate1" runat="server" ReadOnly="true"></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="Search" OnClick="Button1_Click" />
1
  • Could it be that you have different time formats on the server and on the client? Commented Sep 15, 2014 at 8:02

2 Answers 2

1

I don't think read only values is posted back to the server.

You can remove server side ReadOnly and use this on page load.

txtDate1.Attributes.Add("readonly","readonly");

Or you can use Request.Form collection to get the values.

string date1 = Request.Form[txtDate1.UniqueID];
Sign up to request clarification or add additional context in comments.

4 Comments

Sure they are. Elements with disabled do not get posted.
Should I remove it or just make it false?
@AndreiV but .net does not use it.
@NatsuDragneel you need to remove form .aspx and use attribute on page load.
0

Remove ReadOnly="true" from

<asp:TextBox ID="txtDate1" runat="server" ReadOnly="true"></asp:TextBox>

And in code behind add txtDate1.Attributes.Add("readonly", "readonly");

By doing this you can retrieve read-only textbox's value in the code behind.

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.