Site icon Dotnet Helpers

Calling severside method form script

How to call server side method button click event from the client side script :

Script :

<%= Page.ClientScript.GetPostBackEventReference(btnClose, String.Empty) %>;

Note :

Place this code in the script to call the any sever-side method, from above btnclose is the click method of the button. and event is empty.

Calling Script method from server side method.

System.Web.UI.ScriptManager.RegisterClientScriptBlock(Page, typeof(Page), “Script”, “ConfirmationAlert();”, true);

Note :

ConfirmationAlert()  method :

 function ConfirmationAlert() {
var copiedText = “”;
var answer = confirm(“Click ‘OK’, to give alert!”)
if (answer) {
alert(“You Click OK”);}}

Exit mobile version