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" />
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?
source to share
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.
source to share
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.
source to share