asp.net給Silverlight程式傳引數

iDotNetSpace發表於2009-12-29

web程式方面:

第一步:建立跳轉頁面,給呼叫Silverlight的頁面傳遞引數

頁面程式碼:

    TagPrefix="asp" %>

ttp://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" target=_blank>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頁面中

頁面程式碼:

    TagPrefix="asp" %>

ttp://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" target=_blank>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部落格 ” ,連結:http://blog.itpub.net/12639172/viewspace-623868/,如需轉載,請註明出處,否則將追究法律責任。

相關文章