Arnaud Ad Arnaud Ad - 1 month ago 14
ASP.NET (C#) Question

OnClick not working when i use both Onclick & OnClientClick

With this code, i try to Close a Window (the way i'm doing it works) but i have also an Onclick event which is ignored!

<script type="text/javascript">


function GetRadWindow() {
var oWindow = null;
if (window.radWindow) oWindow = window.radWindow;
else if (window.frameElement.radWindow) oWindow = window.frameElement.radWindow;
return oWindow;
}

function CloseDialog() {
GetRadWindow().close();

}




ASPX page:

<asp:Button ID="Button1" runat="server" Text="Soumettre ce ticket"
onclick="Button1_Click" OnClientClick="CloseDialog();return false;"/>


My application never enters Button1_click event, can anyone help me to find out why ?
thanks in advance

EDIT: HTML GENERATED FOR THE BUTTON

<input type="submit" id="Button1" onclick="CloseDialog();" value="Soumettre ce ticket" name="Button1"/>

Answer

This article kind of explains the problem. You need to return true in your JS if you want the server event to trigger. Otherwise, you have to return false.

And, it also looks like you will have to add the UseSubmitBehavior = false based on: OnclientClick and OnClick is not working at the same time?

This is especially evident after seeing that your generated HTML only has the CloseDialog() and not the call to Button1_Click. This change will concatenate to the end of your onclick.

<asp:Button ID="Button1" runat="server" Text="Soumettre ce ticket" 
            onclick="Button1_Click"  OnClientClick="CloseDialog();"  
            UseSubmitBehavior="false"/>
Comments