孟宪会ID:net_lover
[修改头像]
800554次访问,排名32好友200人,关注者1042
http://dotnet.aspx.cc/
【声明:各位好,由于系统“添加好友”功能只能添加200个,后来的朋友不能加入,见谅!!!】
net_lover的文章
原创 228 篇
翻译 1 篇
转载 6 篇
评论 732 篇
孟宪会的公告
欢迎光临!您在阅读的过程中有任何建议或者意见,请发邮件或者留言,合作愉快!
最近评论
LGame:学習
zhspyp:我的IIS(电脑上装的IIS是IIS5.1版)的MetaBase.xml里可以设置上传文件大小,可我的系统(Windows XP 系统)上这个文件是MetaBase.bin(以后辍名.bin为后辍的),在网上搜索了.bin文件打开方式 ,试了很多

虚拟光驱的没用,记事本打开全是乱码,系统上的MetaBase.bin文件只有210K。
MetaBase.bin……
kenth:拜读!
------------------
IOAS:易学易用、灵活自由、个人免费使用的办公系统速成工具。
详情请访问:www.ioas.net
------------------
kenth:收藏研究 感谢!
------------------
IOAS:易学易用、灵活自由、个人免费使用的办公系统速成工具。
详情请访问:www.ioas.net
------------------
zhspyp:net_lover 老师你好!挺崇拜你的!想请你帮个忙!我在其他网站上看到你你信息找你找了好久才能找到你!我的问题你处理过的就是在后台生成静态页面时出现错误!
提示如下:你上次说是! Response.Write request.Form("body")
由于数据量太大,堆栈溢出!

我的问题是:

错误 '80020……
订阅我的博客
XML聚合  FeedSky
文章分类
收藏
    相册
    文章用图
    【孟子E章】站点
    【孟子E章】站点(RSS)
    【孟子E章】网摘(RSS)
    【孟子E章】网站(RSS)
    Silverlight 1.0 SDK 中文版
    Silverlight 1.0 SDK 中文版
    【网上邻居】
    .Net开发资源中心
    【兔子】专栏
    AppleVB 主页
    Estyle(靳田)之狂想手扎
    huahaoyueyuan
    JavaProgramers的专栏
    意玺的BLOG
    最爱白菜
    枕善居VB.NET源码博客
    美丽眼睛看世界
    阿赖
    存档

    原创 Silverlight 2学习教程(五):JavaScript与Silverlight托管代码相互调用

    新一篇: 【英语学习】alpha girl:精英女生

    要实现JavaScript调用Silverlight程序里面的托管代码,需要先在应用程序的启动(Application_Startup)事件里注册要进行访问的对象,而要从Silverlight的托管代码里访问HTML页面对象或者页面中的JavaScript,使用HtmlPage的Document/HtmlElement和HtmlWindow即可。

    下面,我们就以例子来说明两者相互访问的方法,代码里面有很详细的注释,这里不再累述。


    Page.xaml:

    <UserControl x:Class="SilverlightApplication1.Page"
        xmlns
    ="http://schemas.microsoft.com/client/2007" 
        xmlns:x
    ="http://schemas.microsoft.com/winfx/2006/xaml" 
        Width
    ="400" Height="300">
        
    <Grid x:Name="LayoutRoot" Background="White">
            
    <Canvas Canvas.Top="20">
                
    <TextBlock Canvas.Top="10" Canvas.Left="20">请输入您的姓名: </TextBlock>
                
    <TextBox x:Name="UserInput" Width="200" Height="30" Canvas.Top="40" Canvas.Left="20"></TextBox>
                
    <TextBlock x:Name="Msg" Canvas.Top="90" Canvas.Left="20" Foreground="Navy" FontSize="36"></TextBlock>
                
    <Button Click="Button_Click" Content="单击我" FontSize="24" Width="160" Height="60" x:Name="BtnTest" Canvas.Top="160" Canvas.Left="20"></Button>
            
    </Canvas>
        
    </Grid>
    </UserControl>

    Page.xaml.cs:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Documents;
    using System.Windows.Input;
    using System.Windows.Media;
    using System.Windows.Media.Animation;
    using System.Windows.Shapes;
    using System.Windows.Browser;

    namespace SilverlightApplication1
    {
        
    public partial class Page : UserControl
        {
            
    public Page()
            {
                InitializeComponent();
            }


            
    private void Button_Click(object sender, RoutedEventArgs e)
            {
                
    string UserInputContent = this.UserInput.Text;
                
    if (UserInputContent.Equals(String.Empty))
                {
                    UserInputContent 
    = "Hello Silverlight World!";
                }
                
    else
                {
                    UserInputContent 
    = "你好," + UserInputContent;
                }
                HtmlWindow win 
    = HtmlPage.Window;
                
    this.Msg.Text = UserInputContent;
                win.Alert(
    "Silverlight 里面弹出的对话框。 " + UserInputContent);
                
    //执行页面中的js函数:
                win.Eval("getArrayTest()");
                Object[] args 
    = { "将此参数传递给 js 函数" };
                win.Invoke(
    "getArrayTest", args);
                
    //如果页面中的值
                HtmlDocument doc = HtmlPage.Document;
                doc.GetElementById(
    "UserName").SetAttribute("value"this.UserInput.Text);
            }

            [ScriptableMember()]
            
    public string InterInvole()
            {
                
    string username = HtmlPage.Document.GetElementById("UserName").GetAttribute("value");
                
    this.UserInput.Text = username;
                
    this.Msg.Text = "您输入了:" + username; 
                
    return "你从js脚本中调用了 Silverlight 里面的方法。";
            }
        }
    }



    App.xaml.cs:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Documents;
    using System.Windows.Input;
    using System.Windows.Media;
    using System.Windows.Media.Animation;
    using System.Windows.Shapes;
    using System.Windows.Browser;

    namespace SilverlightApplication1
    {
        
    public partial class App : Application
        {

            
    public App()
            {
                
    this.Startup += this.Application_Startup;
                
    this.Exit += this.Application_Exit;
                
    this.UnhandledException += this.Application_UnhandledException;

                InitializeComponent();
            }

            
    private void Application_Startup(object sender, StartupEventArgs e)
            {
                
    // Load the main control           
                Page p = new Page();
                HtmlPage.RegisterScriptableObject(
    "SilverlightApplicationExample", p);

                
    // 请注意这里的定义方法,如果这里的p写成 new Page(),则Javascript基本不能给 UserInput 赋值!
                this.RootVisual = p;
            }

            
    private void Application_Exit(object sender, EventArgs e)
            {

            }
            
    private void Application_UnhandledException(object sender, ApplicationUnhandledExceptionEventArgs e)
            {

            }
        }
    }

    SilverlightApplication1TestPage.aspx:

    <%@ Page Language="C#" AutoEventWireup="true" %>

    <%@ Register Assembly="System.Web.Silverlight" Namespace="System.Web.UI.SilverlightControls" TagPrefix="asp" %>
    <!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>Silverlight 2托管代码与Javascript交互的例子</title>
     
    <script type="text/javascript">
     
    //<!{CDATA[
     //定义全局变量:
     var testVar = "孟宪会";
     
     
    //定义全局函数:
     function getArrayTest()
     {
      
    if(arguments.length > 0)
      {
       alert(
    "js 对话框:您传递了参数。" + arguments[0]);
       
    return  arguments[0];
      }
      
    else
      {
       alert(
    "js 对话框:无参数调用。");
       
    return "js 函数返回值";
      }
     } 
     
    function SetUserName()
    {
      alert(SilverlightPlugin.Content.SilverlightApplicationExample.InterInvole());
    }

    //定义Silverlight插件对象
    var SilverlightPlugin = null;;
    function pluginLoaded(sender)
    {
       SilverlightPlugin 
    = sender.get_element();  
    }
     
    //]]>
     </script>
    </head>
    <body style="height: 100%; margin: 0;">
     
    <form id="form1" runat="server">
     
    <div style="border: 2px solid #EEE; margin: 20px;padding:20px">
      请输入你的名字:
    <input id="UserName" type="text" value="" />
      
    <input type="button" onclick="SetUserName()" value="将名字传递到 Silverlight" />
     
    </div>
     
    <br />
     
    <div style="border: 2px solid #EEE;margin: 20px;">
      
    <asp:ScriptManager ID="ScriptManager1" runat="server">
      
    </asp:ScriptManager>
      
    <asp:Silverlight ID="Xaml1" runat="server" OnPluginLoaded="pluginLoaded" Source="~/ClientBin/SilverlightApplication1.xap" Version="2.0" Width="400px" Height="300px" />
     
    </div>
     
    </form>
    </body>
    </html>
     

    运行结果:

    发表于 @ 2008年04月10日 00:13:00|评论(loading...)|编辑

    旧一篇: 【英语学习】flash mob:快闪族

    评论

    #chaye12 发表于2008-04-10 08:57:36  IP: 60.210.228.*
    看了两边,还是不太明白,Application_Startup事件还不知道在哪呢!真是愚钝!
    2008-04-10 09:07:18作者回复
    App.xaml.cs里面
    #chaye12 发表于2008-04-10 09:25:33  IP: 60.210.228.*
    恩,知道了,我的是2.0可能不太行!
    #dymo17 发表于2008-04-10 17:15:02  IP: 211.151.230.*
    debug可以正常运行,
    但部署后点击页面上的按钮说找不到下面这个对象:
    SilverlightPlugin.Content.SilverlightApplicationExample

    点击Silverlight对象内的“单击我”按钮,msg能正常显示UserInput输入的内容,但没有继续执行后面的传递参数的动作。

    IIS配置:
    asp.net 2.0.50727
    MIME类型 application/xaml+xml

    这是什么原因?
    发表评论  


    当前用户设置只有注册用户才能发表评论。如果你没有登录,请点击登录
    Csdn Blog version 3.1a
    Copyright © 孟宪会