Validation control

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
 
G

Guest

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
 
B

BlackMagic

You could set the CausesValidation property of your Cancel button to False.
This has worked for me.

HTH
 

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

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,901
Latest member
Noble71S45

Latest Threads

Top