0

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....

6
  • 1
    Communicate to do what? What have you go so far? Have you any code you can show us? Commented May 14, 2014 at 12:42
  • i didnt even understand what are two applications here :) no offence Commented May 14, 2014 at 12:44
  • 1
    Do you have a "browser control" on you C# app and want to control the "outside" app from "inside" the browser control? Commented May 14, 2014 at 12:45
  • Maybe you want ajax communication? not sure what you want from your question Commented May 14, 2014 at 12:45
  • 1
    There is no two applications, I'm using webform on-top of regular form. I like to send events from the webform to the actual application. I created a Skin folder with all the html / js files and I direct the url of the webform to display the files there Commented May 14, 2014 at 12:49

2 Answers 2

2

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
}
Sign up to request clarification or add additional context in comments.

1 Comment

Did you find the correct event? Can you tell us what "browser control" you are using so I can use the correct names/types in my example?
2

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) 
{
    ...
}

5 Comments

I need to add sever side behavior to my client to accomplish that?
If you are in a .ascx or .aspx control, then you need to add server side controls to fire events that "trigger" actions on the back end. You can always use other server-side controls or bee-stings to render content from the back-end onto the front end. Does that answer your question?
Sure - you should check out the MSDN docs for the WebControl that you would like to use, and look at the events that it supports. For example, if you want to fire an event on a button click, look at the docs for the ".NET Button control". If you ever don't know the control you are looking for, you can always search for ".NET xxxxx control" where "xxxxx" would be the HTML tag associated with the control.
For example, here are the docs for the Button control: msdn.microsoft.com/en-us/library/…
Be aware that there is a little drop-down under the name of the control in the docs from which you can select the version of .NET that you are using. Most controls haven't changed much between versions, but it is best to look at the docs for the version that you are using.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.