Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
162 views
in Technique[技术] by (71.8m points)

c# - What is the use of window.external?

What is the use of window.external? Is this used to call the server side functions / methods in C# / VB.NET (ASP.NET) from JavaScript? Can you please point me in right direction?

Code:

<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="WebForm1.aspx.vb" Inherits="WebApplication1.WebForm1" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <input type="button" name="button1" value="Click" 
               onclick="javascript:window.external.SayHello('Mike');" />
    </div>
    </form>
</body>
</html>
Public Class WebForm1
    Inherits System.Web.UI.Page

    Public Sub SayHello(ByVal name As String)
        Response.Write("Hello :- " & name)
    End Sub
End Class
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

This is largely taken from this MSDN article but window.external can be used to allow your WebBrowserControl to execute public methods of your client Windows Forms application.

For example in your form you may have a function such as:

public void HelloFromTheForm()
{
    MessageBox.Show("Hi client, thanks for calling me!");
}

And in the html loaded into your WebBrowserControl you may have a button that looks like:

<button onclick="window.external.HelloFromTheForm()">
    Say hi to the form
</button>

So in regards to your question of 'Is this used to call the server side functions?', your form isn't 'server side' but it does allow you to call the C#/VB.NET code of your form from an embedded webpage.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...