problem with customvalidator

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jeff

    problem with customvalidator

    hey

    net 3.5

    I have problem with a customvalidator . I enter values into the TextBox named
    "txt" and clicks on the save button (ibSave) then the TestValidate method
    get triggered. TestValidate set args.IsValid = false and the customvalidator
    displays an error on the webpage. The problem is that when I check in the
    database, the value has still been added to the database. if the value
    entered in the TextBox is not a correct value, then I want it not store it
    in the database...

    below are my markup and code-behind

    <asp:TextBox ID="txt" runat="server"> </asp:TextBox>
    <asp:CustomVali dator ID="valCustom" ControlToValida te="txt"
    OnServerValidat e="TestValidate " Display="Dynami c" runat="server"
    ErrorMessage="C ustomValidator" ></asp:CustomValid ator>
    <asp:ImageButto n ID="ibSave" ImageUrl="~/Images/Go.gif"
    OnClick="ibSave _method" runat="server" />

    protected void TestValidate(ob ject source, ServerValidateE ventArgs args)
    {
    // do some processing/
    args.IsValid = false;
    }


    any suggestions?


  • =?Utf-8?B?YnJ1Y2UgYmFya2Vy?=

    #2
    RE: problem with customvalidator

    your save code probably does not check IsValid:

    if (IsValid)
    {
    // do save
    }

    -- bruce (sqlwork.com)


    "Jeff" wrote:
    hey
    >
    net 3.5
    >
    I have problem with a customvalidator . I enter values into the TextBox named
    "txt" and clicks on the save button (ibSave) then the TestValidate method
    get triggered. TestValidate set args.IsValid = false and the customvalidator
    displays an error on the webpage. The problem is that when I check in the
    database, the value has still been added to the database. if the value
    entered in the TextBox is not a correct value, then I want it not store it
    in the database...
    >
    below are my markup and code-behind
    >
    <asp:TextBox ID="txt" runat="server"> </asp:TextBox>
    <asp:CustomVali dator ID="valCustom" ControlToValida te="txt"
    OnServerValidat e="TestValidate " Display="Dynami c" runat="server"
    ErrorMessage="C ustomValidator" ></asp:CustomValid ator>
    <asp:ImageButto n ID="ibSave" ImageUrl="~/Images/Go.gif"
    OnClick="ibSave _method" runat="server" />
    >
    protected void TestValidate(ob ject source, ServerValidateE ventArgs args)
    {
    // do some processing/
    args.IsValid = false;
    }
    >
    >
    any suggestions?
    >
    >
    >

    Comment

    • Jeff

      #3
      Re: problem with customvalidator

      thank you


      "bruce barker" <brucebarker@di scussions.micro soft.comwrote in message
      news:419457C3-B4AC-45FC-92FC-019C5CF0237D@mi crosoft.com...
      your save code probably does not check IsValid:
      >
      if (IsValid)
      {
      // do save
      }
      >
      -- bruce (sqlwork.com)
      >
      >
      "Jeff" wrote:
      >
      >hey
      >>
      >net 3.5
      >>
      >I have problem with a customvalidator . I enter values into the TextBox
      >named
      >"txt" and clicks on the save button (ibSave) then the TestValidate method
      >get triggered. TestValidate set args.IsValid = false and the
      >customvalidato r
      >displays an error on the webpage. The problem is that when I check in the
      >database, the value has still been added to the database. if the value
      >entered in the TextBox is not a correct value, then I want it not store
      >it
      >in the database...
      >>
      >below are my markup and code-behind
      >>
      ><asp:TextBox ID="txt" runat="server"> </asp:TextBox>
      ><asp:CustomVal idator ID="valCustom" ControlToValida te="txt"
      >OnServerValida te="TestValidat e" Display="Dynami c" runat="server"
      >ErrorMessage=" CustomValidator "></asp:CustomValid ator>
      ><asp:ImageButt on ID="ibSave" ImageUrl="~/Images/Go.gif"
      >OnClick="ibSav e_method" runat="server" />
      >>
      >protected void TestValidate(ob ject source, ServerValidateE ventArgs args)
      > {
      > // do some processing/
      > args.IsValid = false;
      > }
      >>
      >>
      >any suggestions?
      >>
      >>
      >>

      Comment

      Working...