By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,077 Members | 1,175 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,077 IT Pros & Developers. It's quick & easy.

Validation control

P: n/a
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
Nov 18 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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
Nov 18 '05 #2

P: n/a
You could set the CausesValidation property of your Cancel button to False.
This has worked for me.

HTH

"simon" <si*********@stud-moderna.si> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
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

Nov 18 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.