problem with customvalidator

J

Jeff

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:CustomValidator ID="valCustom" ControlToValidate="txt"
OnServerValidate="TestValidate" Display="Dynamic" runat="server"
ErrorMessage="CustomValidator"></asp:CustomValidator>
<asp:ImageButton ID="ibSave" ImageUrl="~/Images/Go.gif"
OnClick="ibSave_method" runat="server" />

protected void TestValidate(object source, ServerValidateEventArgs args)
{
// do some processing/
args.IsValid = false;
}


any suggestions?
 
B

bruce barker

your save code probably does not check IsValid:

if (IsValid)
{
// do save
}

-- bruce (sqlwork.com)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,955
Messages
2,570,117
Members
46,705
Latest member
v_darius

Latest Threads

Top