• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 384
  • Last Modified:

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
0
Yurich
Asked:
Yurich
  • 6
  • 4
  • 3
  • +1
2 Solutions
 
appariCommented:
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?
0
 
Sammy AgeilCommented:
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
0
 
YurichAuthor Commented:
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
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
nehayaCommented:
Try add this CausesValidation.. e.g.:
<asp:button id="btnCancel" Runat="server" Text="Cancel" CausesValidation="true"></asp:button>
0
 
YurichAuthor Commented:
thanks, but I'm not looking for the ways to enable validation, I'm after some explanation why it's working in my case.
0
 
appariCommented:
what tools are you using for developing your application?
is it is Visual studio or someother tool?
0
 
YurichAuthor Commented:
vs.net 2003
0
 
Sammy AgeilCommented:
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
0
 
YurichAuthor Commented:
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
0
 
Sammy AgeilCommented:
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
0
 
YurichAuthor Commented:
did you named it as I did?
0
 
Sammy AgeilCommented:
Yes and still triggered the validation event
0
 
appariCommented:

what happens if you start a new webapplication and add new webpage and do the same thing. does the behaviour repeats?
0
 
YurichAuthor Commented:
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
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 6
  • 4
  • 3
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now