문제

I have a C# application that uses WebForm. I am using the WebForm to display my application content (HTML / JavaScript).
My question is how do I communicate between them (API)?

Example: I like to minimize the program by using HTML buttons, etc....

도움이 되었습니까?

해결책

If you have a web browser control on top of a normal control you could use the navigation event. E.g. 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
}

다른 팁

Local or Remote WebForms Application

You can use AJAX if you are trying to communicate with an external (or local) application.

Local WebForms Application

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." 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). 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) 
{
    ...
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top