Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. RequiredFieldValidator doesn't work

RequiredFieldValidator doesn't work

Scheduled Pinned Locked Moved ASP.NET
javascriptsysadminhelptutorialquestion
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    Jan R Hansen
    wrote on last edited by
    #1

    Something must be wrong, as this is probably the most basic validation example ever - yet I still can't get it to work properly, and I actually suspect an error somewhere. Create an aspx page with a textbox, a requiredfieldvalidator and a button. Set the validator to validate the textbox and set its text property to "*". Run the project. Now, I would assume that clicking the textbox and then tabbing to the button would show me the text-message from the validator (the red *), indicating that I haven't entered data where I need. Guess what - it doesn't show up... However, clicking the field, entering data, tabbing away and then back, deleting the data again and then tabbing away again DOES show the red *. Because the validation of the textbox is handled from the onchange event. Try running this in the url field: javascript:void(alert(document.all.TextBox1.onchange)) - it will give you Message from webpage --------------------------- function anonymous() { ValidatorOnChange(event); } , whereas the javascript:void(alert(document.all.TextBox1.onchange)) will return null. Manually hooking the onblur event to the onchange event as so: javascript:void(document.all.TextBox1.onblur=document.all.TextBox1.onchange) will introduce somehow correct behaviour. Now - is it me who has failed to understand the simples of all validation scenarios - or is the requiredfieldvalidator broken. I hope it is the first option, but what the h... am I missing? Sample code:

    <form id="form1" runat="server">
    <div>
    <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
    <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"
    ErrorMessage="RequiredFieldValidator"
    ControlToValidate="TextBox1"
    Text="*"></asp:RequiredFieldValidator>
    <asp:Button ID="Button1" runat="server" Text="Button"/>
    </div>
    </form>

    Do you know why it's important to make fast decisions? Because you give yourself more time to correct your mistakes, when you find out that you made the wrong one. Chris Meech on deciding whether to go to his daughters graduation or a Neil Young concert

    N 1 Reply Last reply
    0
    • J Jan R Hansen

      Something must be wrong, as this is probably the most basic validation example ever - yet I still can't get it to work properly, and I actually suspect an error somewhere. Create an aspx page with a textbox, a requiredfieldvalidator and a button. Set the validator to validate the textbox and set its text property to "*". Run the project. Now, I would assume that clicking the textbox and then tabbing to the button would show me the text-message from the validator (the red *), indicating that I haven't entered data where I need. Guess what - it doesn't show up... However, clicking the field, entering data, tabbing away and then back, deleting the data again and then tabbing away again DOES show the red *. Because the validation of the textbox is handled from the onchange event. Try running this in the url field: javascript:void(alert(document.all.TextBox1.onchange)) - it will give you Message from webpage --------------------------- function anonymous() { ValidatorOnChange(event); } , whereas the javascript:void(alert(document.all.TextBox1.onchange)) will return null. Manually hooking the onblur event to the onchange event as so: javascript:void(document.all.TextBox1.onblur=document.all.TextBox1.onchange) will introduce somehow correct behaviour. Now - is it me who has failed to understand the simples of all validation scenarios - or is the requiredfieldvalidator broken. I hope it is the first option, but what the h... am I missing? Sample code:

      <form id="form1" runat="server">
      <div>
      <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
      <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"
      ErrorMessage="RequiredFieldValidator"
      ControlToValidate="TextBox1"
      Text="*"></asp:RequiredFieldValidator>
      <asp:Button ID="Button1" runat="server" Text="Button"/>
      </div>
      </form>

      Do you know why it's important to make fast decisions? Because you give yourself more time to correct your mistakes, when you find out that you made the wrong one. Chris Meech on deciding whether to go to his daughters graduation or a Neil Young concert

      N Offline
      N Offline
      Not Active
      wrote on last edited by
      #2

      RequiredFieldValidator is a server control and is not evaluated until a postback occurs. The onblur event is handled on the client.


      only two letters away from being an asset

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups