Validating a disabled textbox

Last post 04-11-2007 11:11 PM by brainbug. 3 replies.

Sort Posts:

  • Validating a disabled textbox

    04-11-2007, 8:02 PM
    • Loading...
    • brainbug
    • Joined on 03-09-2006, 9:54 PM
    • Posts 35

    Hello all,

    I have a texbox that requires a date entry but uses a date picker to assign it a date value. But I need to not let users change the date in the textbox and only use the date picker.

    The problem is that if i either make the texbox readonly or diabled it appears that the RequireFieldValidator does not fire for that textbox.

    Any suggestions...........thxTongue Tied

    shane

  • Re: Validating a disabled textbox

    04-11-2007, 9:35 PM
    Answer

    Hi shane,

    I think you can use javascript to make the TextBox to be ReadOnly and the RequiredFieldValidator can still fires

     <asp:TextBox ID="TextBox1" runat="server" BackColor="gray" onkeydown="return false;"></asp:TextBox>
            <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="TextBox1"
                ErrorMessage="RequiredFieldValidator"></asp:RequiredFieldValidator>
            <asp:Button ID="Button1" runat="server" Text="Button" />

    hope it helps,

    Jessica

    Jessica Cao
    Sincerely,
    Microsoft Online Community Support


    “Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread. ”
  • Re: Validating a disabled textbox

    04-11-2007, 11:00 PM
    • Loading...
    • brainbug
    • Joined on 03-09-2006, 9:54 PM
    • Posts 35

    Thx for the suggestion but......

    The onkeydown is not a valid attribute for a asp.net textbox.

    Maybe I could add it via code via the attributes property? Dont know how though thx

     

  • Re: Validating a disabled textbox

    04-11-2007, 11:11 PM
    Answer
    • Loading...
    • brainbug
    • Joined on 03-09-2006, 9:54 PM
    • Posts 35

    Thx to Jessica for pointing me in the right direction I have solved this problem.

    In the page load event add:

     Me.tbox_hearing_date.Attributes.Add("onkeydown", "return false;")

    This will effectivley disable the texbox while allowing validation.

     Thx jessica

Page 1 of 1 (4 items)
Microsoft Communities
Page view counter