Control the Silverlight display value through js on the Asp.net page

Source: Internet
Author: User

Now you need to use buttons to control the values displayed by Silverlight on the interface. The method is as follows.

1. First, compile a method that can be accessed by JS in usercontrol in Silverlight. Note: This method uses the scriptablemember feature.

// How to compile js to access Silverlight , SelectDate is the parameter
[Scriptablemember ()]
Public   Void Gettrendchart ( String SelectDate)
{
Datetime tempdate =   New Datetime ();
If ( String . Isnullorempty (SelectDate) |   ! Datetime. tryparse (SelectDate, Out Tempdate ))
{
Showinfo ( " Incorrect date " );
Return ;
}
// Obtain information and change the Silverlight display value. The createtrendchart ()Code.
Createtrendchart (SelectDate);
}

2. Register this method in APP. XAML.

// Register in APP. XAML
Private   Void Application_startup ( Object Sender, startupeventargs E)
{
// Call usercontrol
This . Rootvisual =   New Trend ();
//How to register JS access
System. Windows. browser. htmlpage. registerscriptableobject ("Trendmethod",This
. Rootvisual );
}

3. Add an onload event to Silverlight on the aspx page.

<% -- Call siliverlight -- %>
< Object Data = "Data: Application/x-silverlight-2 ," Type = "Application/x-silverlight-2"
Width = "100%" Height = "100%" >
< Param Name = "Source" Value = "../Clientbin/iaddtech. Environmental. Web. Silverlight. xap"   />
< Param Name = "Onerror" Value = "Onsilverlighterror"   />
< Param Name = "Background" Value = "White"   />
< Param Name = "Minruntimeversion" Value = "3.0.40818.0"   />
<% -- Add a load event -- %>
param name =" onLoad " value =" silverloaded " />

< Param Name = "Autoupgrade" Value = "True"   />
< Param Name = "Windowless" Value = "True"   />
< A Href = "Http://go.microsoft.com/fwlink? Linkid = 149156 & V = 3.0.40818.0" Style = "Text-Decoration: none" >
< IMG SRC = "Http://go.microsoft.com/fwlink? Linkid = 108181" ALT = "Get Microsoft Silverlight"
Style = "Border-style: none"   />
</ A >
</ Object >

4. Compile the onload event. Get the siliverlight object through the onload event.

< Script Type = "Text/JavaScript" >
VaR Silverlightobj =   Null ;
Function Silverloaded (sender, argS ){
Silverlightobj = Sender. gethost (); // Get siliverlight object
}
</ Script >

5. Add an input on the ASPX page. Use this input to change the display value of Silverlight. The onclick method of this input is gettrenddata.

< Div Class = "Query_button" >
< Input Type = "Image" Value = "Getdate" Onclick = "Gettrenddata (); Return false ;" SRC = "../Resources/images/see_button.jpg"   />
</ Div >

6. Add the input Click Event in Js. Call methods in Silverlight through the Click Event

< Script Type = "Text/JavaScript" >
// Input Click Event
Function Gettrenddata (){
//Silverlightobj has obtained, SelectDate is a parameter for Silverlight
Silverlightobj. content. trendmethod. gettrendchart (SelectDate );
}
</ Script >

In this way, you can use js to control the display value of Silverlight.

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.