Link to home
Start Free TrialLog in
Avatar of Yurich
YurichFlag for New Zealand

asked on

Button btnCancel

Hello,

I have a whole sort of validation controls on my page and it works fine for a submit button I have on the page. I was going to see how I can disable any validation for a cancel button, but apparently I didn't have to... I have an asp.net control button, the name of which is btnCancel, with the text Cancel and when you press it, it doesn't do any validation.

I mean it's smart, but is it hardwired somwhere that a control named Cancel shouldn't do any validation? is it documented anywhere, and what if I want to do some validation for a cancel button?

Thanks,
Yurich
Avatar of appari
appari
Flag of India image

not sure its not happening when i test here on my machine.

if you have causesvalidation property set to false the button click wont cause the validations. may be you have causesvalidation property set to false to this button btncancel.
can you post html source of the btncancel?
what event is the canclebutton wired to? does it suppose to behave like a reset button? if yes then it shouldnt validate anything until you wire it to an event
Avatar of Yurich

ASKER

thanks guys,

html:

<asp:button id="btnCancel" Runat="server" Text="Cancel"></asp:button>

code behind:

            private void btnCancel_Click(object sender, System.EventArgs e)
            {
                  Response.Redirect( "MyProfile.aspx" );
            }

nothing fancy...

any ideas now?
regards,
Yurich
Avatar of nehaya
nehaya

Try add this CausesValidation.. e.g.:
<asp:button id="btnCancel" Runat="server" Text="Cancel" CausesValidation="true"></asp:button>
Avatar of Yurich

ASKER

thanks, but I'm not looking for the ways to enable validation, I'm after some explanation why it's working in my case.
what tools are you using for developing your application?
is it is Visual studio or someother tool?
Avatar of Yurich

ASKER

vs.net 2003
Yurich,
The only reason your button is not triggering the event is because you are not telling it which event its suppose to trigger
if you were to change your code to something like this
-----
<asp:button id="btnCancel" Runat="server" OnClick="btnCancel_Click" Text="Cancel"></asp:button>

code behind:

          private void btnCancel_Click(object sender, System.EventArgs e)
          {
               Response.Redirect( "MyProfile.aspx" );
          }
----
NOTE the "OnClick="btnCancel_Click" in the html button declaration
That code will be executed and the redirect will take happen
If you check your other buttons you will see they trigger an onClick event
Avatar of Yurich

ASKER

2 sammy

I think you missed the point, it DOES trigger its event, it doesn't trigger the validation on the page. And you actually can add manually OnClick in your HTML coding, but if you just double-click you button in the designer, it will not add it into the HTML code.

Regs,
Yurich
Yurich,
I guess I did miss the point :-)
I just added a 2 buttons, textbox and a required validator
no matter which button I click the required validator gets triggered and the execution stops.
I guess you have a blessed button :)

regards
Avatar of Yurich

ASKER

did you named it as I did?
SOLUTION
Avatar of Sammy
Sammy
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Yurich

ASKER

I had to leave this project for a few days and now after I got back to to it, it DOES validating on the Cancel click... Hmm, must be a glitch or something.

Anyway guys, thanks for your help.
Regards,
Yurich