Silverlight xap and HTML Asp.net parameter transfer

Source: Internet
Author: User

Recently, some people have been asking about how to pass parameters between xap and HTML or Asp.net. Next we will learn how to pass this parameter.

First, create a project htmltsilverlight and put a textblock on mainpage to display the parameters passed by the HTML or aspx file;

Next, add the required parameters to htmltsilverlighttestpage.aspx20.htmltsilverlighttestpage.html for the webobject. Generally, there are many server paths passed here. Here we will pass a server path and put a textblock on the mainpage.

XAML:

    <Grid x:Name="LayoutRoot" Background="White">        <TextBlock Height="47" HorizontalAlignment="Left" Margin="52,49,0,0" x:Name="textBlock1" VerticalAlignment="Top" Width="311" />    </Grid>
. CS

 public MainPage()        {            InitializeComponent();            this.textBlock1.Text = App.ServerUrl;        }

Next, modify the htmltsilverlighttestpage.html file in the webproject and add the passing parameters. Htmltsilverlighttestpage. The usage of aspx is the same.

<Body> <Form ID = "form1" runat = "server" style = "height: 100%"> <Div id = "silverlightcontrolhost"> <Object Data = "data: application/x-silverlight-2, "type =" application/x-silverlight-2 "width =" 100% "Height =" 100% "> <Param name =" Source "value =" clientbin/htmltsilverlight. xap "/> <Param name =" onerror "value =" onsilverlighterror "/> <Param name =" background "value =" white "/> <Param name =" minruntimeversion "Value =" 4.0.50826.0 "/> <Param name =" autoupgrade "value =" true "/> <Param name =" initparams "value =" serverurl = http: // 127.0.0.1/service. aspx "/> <a href =" http://go.microsoft.com/fwlink? Linkid = 149156 & V = 4.0.50826.0 "style =" text-Decoration: none ">  </a> </Object> <IFRAME id =" _ sl_historyframe "style =" visibility: hidden; Height: 0px; width: 0px; Border: 0px "> </iframe> </div> </form> </body>

We added a serverurl = http: // 127.0.0.1/service. aspx parameter, which is obtained in mainpage.

We add a static attribute to the app. XAML. CS file for access by other classes. In the parameter startupeventargs of the application_startup event, the Code is as follows:

/// <Summary >/// server path transmitted by HTML or aspx /// </Summary> Public static string serverurl {Get; set ;} private void application_startup (Object sender, startupeventargs e) {// exception handling is required to obtain the parameter ---- serverurl = e if it cannot be obtained. initparams ["serverurl"]. tostring (); this. rootvisual = new mainpage ();}
Finally, set the webproject as the startup project, and htmltsilverlighttestpage.html as the start page. F5 will see the following results. The parameters are retrieved and displayed on the textblock. You can add multiple parameters. Please try them by yourself. Instance code download: http://files.cnblogs.com/Clivia/HtmlTSilverlight.rar
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.