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

cdemott33Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
Introduction to Web Design

Develop a strong foundation and understanding of web design by learning HTML, CSS, and additional tools to help you develop your own website.

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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.