views:

1144

answers:

6

I have a back and next button in that there is a OnClientClick validation function.

This function is not called when i click on that, Please help me

Code has given below:

 <asp:Button ID="btn_view1_back" runat="server" Text="Back" 
                            CausesValidation="False" ValidationGroup="Form2" />

                        <asp:Button ID="btn_View1_Next" runat="server" CausesValidation="true" Text="Next" 
            ValidationGroup="Form2" OnClientClick="return ValidateDropDown();" UseSubmitBehavior ="true"  />
+2  A: 

Just to be sure: ValidateDropDown has been defined in the JavaScript, right? OnClientClick is what is executed on the client side, i.e. the javascript.

The other thing might be that the syntax for OnClientClick might need to be different, such as: OnClientClick="ValidateDropDown()"

AASoft
His syntax is correct, assuming that ValidateDropDown is actually a Javascript method,
SLaks
no hope still not working
Another possibility: if the button is disabeld when the page is rendered, then the OnClientClick event is NOT written to HTML.Is your button disabled when the page is rendered?
AASoft
A: 

The back button is set not to cause validation, and doesn't have an OnClientClick action defined.

Alan
The focus is the "Next" button. I think Jaison didn't describe it too clearly.
o.k.w
yes its next button
A: 

Your ValidateDropDown method is probably throwing an exception, which causes the postback to happen anyway.

Can you post the contents of that method?

Alternatively, use Firebug and check Break on all script errors in the debug menu.

Also, the OnClientClick code runs in the browser, and the method that it calls must be defined in Javascript, not VB.

SLaks
A: 

Make sure that the validation is not firing. It can be that validation is firing and you are not able to see the Text or ErrorMessage since it is blank by default.

azamsharp
A: 

You have a breakpoint in your validate function and it's not getting hit? Or you think it's not getting hit because your page is posting back anyway?

I would expect that ValidateDropDown function to get called, but I'm not sure. However, I also don't think it matters. I don't think it matters because it appears you are looking to prevent a postback and this isn't the way to do that. Are you looking to prevent a postback?

If so, I think the best thing to do here is to ditch the button's OnClientClick and instead add a CustomValidator control for your dropdroplist and then set the ClientValidationFunction to "ValidateDropDown". There's already an asp.net client side validation framework, so I'd just build on that.

But I'm just some idiot from the internet, I barely read your question and my reputation is 16, so I definitely wouldn't listen to me.

chevett
A: 

Your question is a little unclear on which function isn't firing (the JS OnClientClick or the server-side OnClick), but if it's the server-side, make sure ValidateDropDown() is returning true. If it returns false or null or something, the server method won't fire.

Can you post your code for ValidateDropDown? Have you verified that it's firing?

Justin Morgan