简体   繁体   English

如何使用JavaScript从外部调用C#应用程序?

[英]How to call a C# application from outside using JavaScript?

I have a C# application that uses WebForm . 我有一个使用WebForm的C#应用​​程序。 I am using the WebForm to display my application content (HTML / JavaScript). 我正在使用WebForm来显示我的应用程序内容(HTML / JavaScript)。
My question is how do I communicate between them (API)? 我的问题是如何在它们之间进行通信(API)?

Example: I like to minimize the program by using HTML buttons, etc.... 示例:我想通过使用HTML按钮等来最小化程序。

Local or Remote WebForms Application 本地或远程WebForms应用程序

You can use AJAX if you are trying to communicate with an external (or local) application. 如果您尝试与外部(或本地)应用程序进行通信,则可以使用AJAX。

Local WebForms Application 本地WebForms应用程序

If by "application" you are actually referring to the back-end (code-behinds, etc.) of your WebForms project, then the other thing to look into are "server tags," otherwise known as "bee-stings." 如果实际上是通过“应用程序”指的是WebForms项目的后端(代码隐藏等),则要查看的另一件事是“服务器标签”,也称为“ bee-stings”。 Here are just a few exsamples: 以下是一些示例:

<% %>
<%-- --%>
<%# %>
<%= %>

Additionally, you can use event handlers for things like server-side button or anchor clicks, dropdownlist value changes, etc. You can make standard HTML controls server-side by adding the runat="server" attribute, or you can use .NET's WebControls (though they will still have to have the runat="server" attribute). 此外,您可以将事件处理程序用于服务器端按钮或锚点单击,下拉列表值更改等操作。您可以通过添加runat="server"属性来在服务器端创建标准HTML控件,也可以使用.NET的WebControls (尽管它们仍然必须具有runat="server"属性)。 Examples of these would be: 这些示例包括:

Front End 前端

<button runat="server" onserverclick="btn_click">Click me</button>
...
or
...
<asp:Button runat="server" OnClick="btn_click">Click me</asp:Button>

Back End 后端

protected void btn_click(object sender, EventArgs e) 
{
    ...
}

If you have a web browser control on top of a normal control you could use the navigation event. 如果您在常规控件之上具有Web浏览器控件,则可以使用导航事件。 Eg make a link like: 例如,使链接如下:

<a href="#MinimizeWindow">Minimize</a>

And in the navigation event of the browser control (I don't know how the event is actually called - just an example): 在浏览器控件的导航事件中(我不知道该事件的实际调用方式-只是一个例子):

public void browser_OnNavigate(object sender, NavigateArgs e)
{
    if (e.Target == "#MinimizeWindow")
        // minimize and cancel event
    else
        // navigate to target
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM