Validation control

  • Thread starter Thread starter simon
  • Start date Start date
S

simon

I have textBox and field validator on my panel:

<asp:TextBox id="txtID" Runat="server" Text="" Columns="5"></asp:TextBox>
<asp:RequiredFieldValidator id="Requiredfieldvalidator2" runat="server"
ErrorMessage="Enter in the typeID."
ControlToValidate="txtID"></asp:RequiredFieldValidator>

Then I have INSERT and CANCEL buttons.

If the user clicks INSERT button then the txtID should be client and server
validate,
but if user clicks CANCEL button, the validation should be omitted,
panel.visible=false and I show him something else.

Now If I clicks the Cancel button, the validation control doesn't allow me
to post the page.

Does anybody know the solution?

Thank you,
Simon
 
Hi Simon,

You can hide the error message of the RequiredFieldValidation control on the click of CANCEL button by using javascript.
you need to create a function and insert a dummy value for the validation control.Then you need to call this function in the onclick event of the CANCEL Button.

For example:

<head><script lang="Javascript">

function setDummy()

{

var Objtxt = document.getElementById("txtName")

if (Objtxt!=null) {

Objtxt.value ="dummy"

}

}

</script></head><body>
...
<asp:Button id="Button2" style="Z-INDEX: 104; LEFT:192px; POSITION: absolute; TOP: 112px" runat="server"
Width="72px" Text="Cancel" onclick="javascript:setDummy();"></asp:Button>

Now,you will not see the error message on the click of CANCEL button.

Hope that helps
Regards
Lakshmi
 
You could set the CausesValidation property of your Cancel button to False.
This has worked for me.

HTH
 
Back
Top