-9

I am trying to do the page level validation in javascript for and element and if the validation is passed i want to call the codebehind method .cs file method of .aspx.cs file method. Can anyone please provide any details / code which will make this requirement work in an easy way. I am trying to do this in C# .net. Thanks,

Aditya
  • 65
  • 1
  • 7

1 Answers1

2

I doubt this is possible...in a direct and easy way. Javascript code is client-side, cs codebehind is server side code.

Usually, the way to "use", or "access" .NET code and methods you need from Javascript (but this applies in general to server-side code) is to expose these methods as a service. Possibly, a REST service or a web-service. See WCF and other frameworks (e.g. ServiceStack) on how to create it. I particularly like ServiceStack; it is simple to use and gets things done in a minute!

A useful list can be found in this answer

Community
  • 1
  • 1
Lorenzo Dematté
  • 7,638
  • 3
  • 37
  • 77