OnClientClick doesn't work

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

This function is not called when I click on it, please help me

The code is 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


source to share


6 answers


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



Another thing is that the syntax for OnClientClick may be different, for example: OnClientClick = "ValidateDropDown ()"

+3


source


Your question is a bit unclear as to which function doesn't get triggered (JS OnClientClick or server side OnClick), but if it's server side, make sure it ValidateDropDown()

returns true

. If it returns false

or null

or whatever, the server method won't fire.



Can you post your code for ValidateDropDown? Have you confirmed that he is shooting?

+1


source


The back button is configured to not trigger validation and has no OnClientClick action set.

0


source


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

Can you post the content of this method?

Alternatively use Firebug and check Break on all script errors

in the debug menu.

Additionally, the code OnClientClick

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

0


source


Make sure the check fails. It may happen that the check is being performed and you cannot see the text or the ErrorMessage as it is empty by default.

0


source


Do you have a breakpoint in your validation function and it doesn't hit? Or do you think it missed because your page is posting anyway?

I would expect the ValidateDropDown function to be called, but I'm not sure. However, I also don't think this is important. I don't think this is important because it seems like you want to prevent postbacks and this is not the way to do it. Do you want to prevent postback?

If so, I think the best thing to do here is to fire the OnClientClick button and instead add a CustomValidator control to your dropdroplist and then set the ClientValidationFunction to "ValidateDropDown". There is already an asp.net client side authentication framework out there, so I'll just describe it.

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

0


source







All Articles