-2

I have a HTML page and I need it to invoke some methods defined by a .NET Class Library project.

For example, there is a list of blocked websites defined by the network administrator. When the user accesses a blocked website, a HTML error page is automatically thrown. I want this error page, when loaded, to call the "SomeFunction()" method, which is defined in the class library project.

Is that possible?

cgalvao1993
  • 148
  • 2
  • 18
  • it maybe easier to implement this at firewall level. – Ray Cheng May 28 '13 at 18:31
  • 1
    Your question doesn't make much sense. To begin with, you can't implement a DLL using javascript. – Icarus May 28 '13 at 18:32
  • Maybe the answers [here](http://stackoverflow.com/questions/3713/call-asp-net-function-from-javascript) will help. – Tung May 28 '13 at 18:34
  • @Icarus: Ok, didn't know that. Please focus on my scenario: a html page that when loaded calls a function defined by a .net class library. Thats it – cgalvao1993 May 28 '13 at 18:41
  • 1
    What server are you hosting it on, ASP.net, PHP? It is impossible to achieve, if you do not use any kind of server. – Rasmus Søborg May 28 '13 at 18:42
  • @Tung Everything in the post you mentioned is about .net environment. My page is in html, trying to call a method inside a .net class library. – cgalvao1993 May 28 '13 at 18:43
  • @dotTutorials it runs on Apache, only html – cgalvao1993 May 28 '13 at 19:04
  • If you really must have javascript invoke anything from a DLL you will need to write a COM wrapper around the dll, install the dll, wrapper, .NET framework on the client machine, tweak security so javascript can invoke the call, than call the COM wrapper from javascript..lots of work and likely not what you're asking. – PeskyGnat May 28 '13 at 19:04
  • And, and alternative may be to look into Silverlight http://www.codeproject.com/Articles/293515/Calling-Silverlight-Method-from-Javascript-and-Jav – PeskyGnat May 28 '13 at 19:09
  • @PeskyGnat wow, didn't imagine how toilsome this is. Is there another way? I've heard about ajax and json but don't know if is possible working only with html – cgalvao1993 May 28 '13 at 19:09

2 Answers2

2

You can achieve what you are requesting. You can not, however; directly call a .dll file from JavaScript. If you want to call a function from a .NET dll in JavaScript, you will have to pass some parameters to your server and then get a response.

My best guess would be, that you will have to use JSON and ajax to do just that job. I would suggest you to look further into ASP.Net. Here's a good start.

Rasmus Søborg
  • 3,597
  • 4
  • 29
  • 46
0

Are you using MVC? You can search for "Strongly Typed Views", in this case you can call these methods.

See this: Strongly Typed Views

Community
  • 1
  • 1
Wellington Zanelli
  • 1,894
  • 3
  • 18
  • 43