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();
}