ITPub博客

首页 > Linux操作系统 > Linux操作系统 > asp.net给Silverlight程序传参数

asp.net给Silverlight程序传参数

原创 Linux操作系统 作者:iDotNetSpace 时间:2009-12-29 14:56:58 0 删除 编辑

web程序方面:

第一步:创建跳转页面,给调用Silverlight的页面传递参数

页面代码:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="SilverlightApplication2.Web.WebForm1" %>

<%@ Register Assembly="System.Web.Silverlight" Namespace="System.Web.UI.SilverlightControls"
    TagPrefix="asp" %>

http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
http://www.w3.org/1999/xhtml" >

    SilverlightApplication2


   
       
       


           
       

   

cs代码:

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

namespace SilverlightApplication2.Web
{
    public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            Response.Redirect(String.Format("WebForm1.aspx?SongUrl={0}&SongSinger={1}&SongName={2}", this.SongUrl.Text, this.SongSinger.Text, this.SongName.Text));
        }
    }
}

第二步:在调用Silverlight页面中

页面代码:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="SilverlightApplication2.Web.WebForm1" %>

<%@ Register Assembly="System.Web.Silverlight" Namespace="System.Web.UI.SilverlightControls"
    TagPrefix="asp" %>

http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
http://www.w3.org/1999/xhtml" >

    SilverlightApplication2


   
       
       


           
       

   

cs代码:

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

namespace SilverlightApplication2.Web
{
    public partial class WebForm1 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {


            this.Xaml1.InitParameters = String.Format("SongUrl={0},SongSinger={1},SongName={2}", Request.QueryString["SongUrl"], Request.QueryString["SongSinger"], Request.QueryString["SongName"]);

        }
    }

Silverlight程序设计

第一步:在app.xaml的Application_Startup事件中

        private void Application_Startup(object sender, StartupEventArgs e)
        {
            Page page = new Page();
            page.SongUrl = e.InitParams["SongUrl"];
            page.SongSinger = e.InitParams["SongSinger"];
            page.SongName = e.InitParams["SongName"];
            this.RootVisual = page;
        }

第二步:page.xaml 定义如下

        public string SongUrl;
        public string SongSinger;
        public string SongName;
       

       这样就达到了传递参数的目的

环境:asp.net2008 sp1 +Silverlight3

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/12639172/viewspace-623868/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2008-01-04

  • 博文量
    2376
  • 访问量
    5766154