Skip to content Skip to sidebar Skip to footer

C# Onclick And Onclientclick At The Same Time

I have onclientclick and onclick events written for Exit button on my webpage. When clicked, it should first execute the update statement and then close the window.

Solution 1:

OnClientClick is executed before the postback happens. It is usually used for things like client side validation where you need to prevent the postback from happening by using return false. Since you are always returning from your handler, the postback will never execute and thus the server side handler will not be called as well.

You need to remove the OnClientClick property and instead call this line in your server side handler:

ScriptManager.RegisterStartupScript(this, this.GetType(), "windowclose", "self.close();", true);

This will cause the window to be closed after the postback executes and the result is returned to the browser. This will also mean that if the update ends with an exception, the window is not closed.

Post a Comment for "C# Onclick And Onclientclick At The Same Time"