Learning Silverlight 2 Series (21): How to invoke JavaScript in Silverlight

Source: Internet
Author: User
Tags silverlight

Support for HTML, client script, and so on is built into Silverlight. In many cases, the Web applications we write use some JavaScript or Ajax frameworks, and we want to be able to invoke certain scripting methods in Silverlight, or trigger the execution of a script in Silverlight. You need to invoke JavaScript in Silverlight, as this article briefly describes.

Using GetProperty to get script objects

Let's look at a simple example of putting a div in the Silverlight test page as a display message:

<div id="result"></div>

Write a simple JavaScript code:

<script type="text/javascript">
  function Hello (message)
  {
    var resultSpan = $get("result");
     resultSpan.innerText = "Hello " + message;
  }
</script>

Then write a simple input information interface:

<StackPanel Background="#CDFCAE" Orientation="Vertical">
  <StackPanel Height="40">
     <TextBlock Text="Calling Browser Script from Silverlight"
          Foreground="Red"></TextBlock>
   </StackPanel>
  <StackPanel Orientation="Horizontal">
    <TextBox x:Name="input" Width="340" Height="40" Margin="20 0 20 0"></TextBox>
     <Button x:Name="submit" Width="120" Height="40" Background="Red"
      Content="调 用" FontSize="20" Foreground="Red" Click="submit_Click"></Button>
   </StackPanel>
</StackPanel>

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.