• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1804
  • Last Modified:

ASP.NET RequiredFieldValidator on a ReadOnly Textbox

I have a textbox on my form used to hold the value of a date.   Rather than having the user enter a date in the text box the textbox is set to ReadOnly and the user must use a date picker to select a date.  Once they select a date the date value is pasted to the readonly textbox.

My problem is with the RequiredFieldValidator for this ReadOnly textbox.  For some reason when a date is selected and passed to the ReadOnly field the RequiredFieldValidator believes there is nothing there?

How can I fix this?


<tr>
            <td class="style3">
                <asp:RequiredFieldValidator 
                    ID="rfv_ShowStartDate" 
                    runat="server" 
                    ErrorMessage="Please select a Date from the calendar dropdown." 
                    ControlToValidate="tbStartDate" 
                    Display="Dynamic" 
                    Text="*">
                </asp:RequiredFieldValidator>&nbsp;             
                Show Start Date:</td>
            <td>
                <asp:TextBox ID="tbStartDate" runat="server" ReadOnly="True"></asp:TextBox>
                <obout:Calendar ID="Calendar1" runat="server" 
                    DatePickerImagePath="images/datepicker_icon.gif" DatePickerMode="True" 
                    StyleFolder="obout_calendar/styles/default" TextBoxId="tbShowStartDate">
                </obout:Calendar>
            </td>
        </tr>

Open in new window

0
cdemott33
Asked:
cdemott33
1 Solution
 
afumedoCommented:
This is Here is a workaround for this problem:

http://support.microsoft.com/kb/917733

1- Delete the ReadOnly attribute from the control declaration. Alternatively, set the ReadOnly attribute to false.

2- Programmatically set the ReadOnly attribute to true.

    protected void Page_Load(object sender, EventArgs e)
    {
        this.TextBox1.ReadOnly = true;
    }

Best wishes,

Ahmed Bedier
0
 
rajapandian_81Commented:
Instead of setting ReadOnly, set contenteditable like below:


<asp:TextBox ID="tbStartDate" runat="server" contenteditable="false"></asp:TextBox>

Open in new window

0
 
meispiscesCommented:
None of server side validations will work when text box is set to read only. You could either remove read only or could validate it by JavaScript (What to validate: The user enters/picks correct date)
0
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

 
cdemott33Author Commented:
I was surprised that afumedo solution didn't work, becuase it was from Microsoft.  However the contenteditable="false" worked.  I never heard of that attribute but its works.
0
 
afumedoCommented:
Doesn't my comment look like an an answer to your question ?!! did it work for you ?
0
 
cdemott33Author Commented:
Unfortunately it didn't work?  I'm not exactly sure why... I mean.. that's what Microsoft has as a fix??? But for me, it didn't make a difference.  The only thing that worked as contenteditable="false".  
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now