NitroFrost
NitroFrost

Reputation: 153

ASP.NET event that triggers both a javascript function then a c# function

I would like to accomplish an on click event to preform 2 functions sequentially

< onclick=" JavaScriptFunction() , C#ServerSideFunction()">

how would I go about this. I have found an example of how to do 2 javascript functions sequentially but not both.

Upvotes: 0

Views: 254

Answers (2)

levininja
levininja

Reputation: 3248

Have it call a js function, and have that function call the js function you want first, and then call the C# function.

You can call a C# function from js using AJAX. Here's an example post about that:

Calling functions from an ASP.NET code file with javascript

And here's a whole blog post about calling C# from js:

http://www.c-sharpcorner.com/UploadFile/abhikumarvatsa/calling-an-Asp-Net-C-Sharp-method-web-method-using-javascript/

Upvotes: 1

m.edmondson
m.edmondson

Reputation: 30892

What you'll essentially need to do is call a javascript function (which performs your client-side activities) which when finished makes your postback to the server.

In order for javascript to perform the postback you would use:

__doPostBack('<%=btnPlaceHolder.UniqueID %>', '')

as per this question.

Upvotes: 2

Related Questions