aspx页面中点击按钮传递给Silverlight,并且页面不刷新

简介: function onSilverlightError(sender, args) { var ap...
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Index.aspx.cs" Inherits="test.Index" %>

<!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>
    <script src="Scripts/jquery-1.4.1.min.js" type="text/javascript"></script>
    <script src="Silverlight.js" type="text/javascript"></script>
    <script type="text/javascript">
        function onSilverlightError(sender, args) {
            var appSource = "";
            if (sender != null && sender != 0) {
                appSource = sender.getHost().Source;
            }

            var errorType = args.ErrorType;
            var iErrorCode = args.ErrorCode;

            if (errorType == "ImageError" || errorType == "MediaError") {
                return;
            }

            var errMsg = "Silverlight 应用程序中未处理的错误 " + appSource + "\n";

            errMsg += "代码: " + iErrorCode + "    \n";
            errMsg += "类别: " + errorType + "       \n";
            errMsg += "消息: " + args.ErrorMessage + "     \n";

            if (errorType == "ParserError") {
                errMsg += "文件: " + args.xamlFile + "     \n";
                errMsg += "行: " + args.lineNumber + "     \n";
                errMsg += "位置: " + args.charPosition + "     \n";
            }
            else if (errorType == "RuntimeError") {
                if (args.lineNumber != 0) {
                    errMsg += "行: " + args.lineNumber + "     \n";
                    errMsg += "位置: " + args.charPosition + "     \n";
                }
                errMsg += "方法名称: " + args.methodName + "     \n";
            }

            引发新错误(errMsg);
        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:ScriptManager ID="ScriptManager1" runat="server">
        </asp:ScriptManager>
        <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
            <ContentTemplate>
                <input type="button" class="btn-search" value="查询" id="btnSearch" />
                <div style="width: 100%; height: 700px">
                    <object id="SL" data="data:application/x-silverlight-2," type="application/x-silverlight-2"
                        width="100%" height="700px">
                        <param name="source" value="ClientBin/SL.xap" />
                        <param name="onError" value="onSilverlightError" />
                        <param name="background" value="white" />
                        <param name="minRuntimeVersion" value="4.0.60310.0" />
                        <param name="autoUpgrade" value="true" />
                        <param name="windowless" value="true" />
                        <a href="http://go.microsoft.com/fwlink/?LinkID=149156&v=4.0.60310.0" style="text-decoration: none">
                            <img src="http://go.microsoft.com/fwlink/?LinkId=161376" alt="获取 Microsoft Silverlight"
                                style="border-style: none" />
                        </a>
                    </object>
                </div>
            </ContentTemplate>
        </asp:UpdatePanel>
    </div>
    </form>
</body>
</html>
<script type="text/javascript" language="javascript">
    $(document).ready(function () {
        $("#btnSearch").click(function () {
            getMess();
        });
    });

    function getMess() {
        $.post("Index.aspx", {
            "action": "search",
            "param": "level"
        }, function (data) {
            setTimeout(function () {
                var slHost = document.getElementById("SL");
                var page = slHost.Content.Page;
                page.process(data);
            }, 1000);
        });
    }
</script>

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;

namespace test
{
    public partial class Index : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (Request["action"] != null)
                {
                    if (Request["param"] != null)
                    {
                        System.Web.Script.Serialization.JavaScriptSerializer jss = new System.Web.Script.Serialization.JavaScriptSerializer();
                        StringBuilder sb = new StringBuilder();
                        sb.Append(Request["param"].ToString());
                        string strs = jss.Serialize(sb.ToString());
                        Response.Write(sb.ToString());
                        Response.End();
                    }
                }
                else
                {

                }
            }
        }
    }
}

<UserControl x:Class="SL.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d"
    d:DesignHeight="300" d:DesignWidth="400">

    <Grid x:Name="LayoutRoot" Background="White">

    </Grid>
</UserControl>

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
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 SL
{
    public partial class MainPage : UserControl
    {
        public MainPage()
        {
            InitializeComponent();
            HtmlPage.RegisterScriptableObject("Page", this);
        }

        [ScriptableMember]
        public void process(string arg)
        {
            if (arg.Length > 0)
            {
                MessageBox.Show(arg);
            }
        }
    }
}


相关文章
|
前端开发 .NET 开发框架
Silverlight页面在兼容/高速模式下出现滚动条的解决办法
在asp.net web项目中承载Silverlight项目的页面,在搜狗高速模式下正常,在兼容模式下出现竖直滚动条,如何去除? 将承载Silverlight的测试页中的以下标识进行修改。
706 0
|
.NET 索引 开发框架
asp.net 图片批量上传预览,在Silverlight页面中读取并滚动显示
Silverlight动态读取图片并滚动显示 asp.net页面中图片上传并预览   ...
651 0
|
监控 前端开发 API
ArcGIS API for Silverlight 点击地图弹出自定义窗体
在之前的博客中,关于弹出窗体,样式比较单一,不能满足自定义各种样式,源连接地址:http://blog.
574 0
|
前端开发 API 开发工具
ArcGIS API for Silverlight开发中鼠标左键点击地图上的点弹出窗口及右键点击弹出快捷菜单的实现代码
1、首先在SL项目中添加一个抽象类ContextMenu.cs文件,代码如下: using System; using System.
1215 0

热门文章

最新文章

下一篇
无影云桌面