Silverlight Pass Value Implementation

Source: Internet
Author: User
Tags static class silverlight

Many developers are starting from. NET Web site development to Silverlight transformation process often will experience a relatively depressed over the period: Silverlight as embedded in the Web page plug-ins, how can be like the traditional ASP.net Web page to achieve page switching and parameter transfer and so on often tied to everyone. We have to talk about the nature of the problem.

Asp. NET Web site is primarily server-based development (runat= "Server"); because it runs on the server, the ASPX dynamic page operates on server-side objects, such as accessing databases in the server, and Silverlight is the standard client plug-in (< Object ...) , if you remove its web-page shell (out-of-browser), its shape is almost the same as the client software, and it can interact directly with the user's computer in a safe use, and instead, if you want to access a database on a server in a network through Silverlight, you must Drive A third party, such as WCF, as a transport intermediary.

Therefore, for the novice Silverlight friend I strongly recommend that you deeply distinguish between the server side and the client, just as when learning asp.net, you must distinguish between server-side controls and client controls.

Let's take a look at an example: we create a Silverlight application Web site that will include two projects in the entire solution for Silverlight projects and Web site projects, respectively, for comparative analysis, We add a asp.net page to the Web site project, and then write the same static class Global.cs in each of the two projects:

public static class Global {
         public static int num = 50;
}

Then add a button to the Index.aspx page with a num value of 50 added per click:

Index.aspx:

<div>
         <asp:Button ID="button1" Text="确定" runat="server" OnClick="button1_OnClick" />
         <asp:TextBox ID="textBox1" runat="server" />
     </div>

Index.aspx.cs:

protected void button1_OnClick(object sender, EventArgs e) {
             Global.num += 50;
             textBox1.Text = Global.num.ToString();
         }

Also add a button to the MainPage.xaml, and the NUM value increases by 50 per click:

MainPage.xaml:

<Canvas>
         <Button x:Name="button1" Content="确定" Click="button1_Click"/>
         <TextBox x:Name="textBox1" Canvas.Left="30" Width="85" />
     </Canvas>

MainPage.xaml.cs

private void Button1_Click(object sender, RoutedEventArgs e) {
             Global.num += 50;
             textBox1.Text = Global.num.ToString();
         }

Large-Scale Price Reduction
  • 59% Max. and 23% Avg.
  • Price Reduction for Core Products
  • Price Reduction in Multiple Regions
undefined. /
Connect with us on Discord
  • Secure, anonymous group chat without disturbance
  • Stay updated on campaigns, new products, and more
  • Support for all your questions
undefined. /
Free Tier
  • Start free from ECS to Big Data
  • Get Started in 3 Simple Steps
  • Try ECS t5 1C1G
undefined. /

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.