使用Master页面中的控件和属性 一

Master页面:
 
  
1 <% @ Master Language = " C# " %>
2
3 < script runat = " server " >
4 protected void Page_Load( object sender, EventArgs e)
5 {
6 if ( ! Page.IsPostBack)
7 {
8 Label1.Text = System.Guid.NewGuid().ToString();
9 }
10 }
11 </ script >
12
13 < html xmlns = " http://www.w3.org/1999/xhtml " >
14 < head id = " Head1 " runat = " server " >
15 < title > My Company Master Page </ title >
16 < asp:ContentPlaceHolder id = " head " runat = " server " >
17 </ asp:ContentPlaceHolder >
18 </ head >
19 < body >
20 < form id = " form1 " runat = " server " >
21 < table cellpadding = " 3 " border = " 1 " >
22 < tr bgcolor = " silver " >
23 < td colspan = " 2 " >
24 < h1 > My Company Home Page </ h1 >
25 < b > User ' s GUID:&nbsp;&nbsp;
26 < asp:Label ID = " Label1 " Runat = " server " /></ b >
27 </ td >
28 </ tr >
29 < tr >
30 < td >
31 < asp:ContentPlaceHolder ID = " ContentPlaceHolder1 "
32 Runat = " server " >
33 </ asp:ContentPlaceHolder >
34 </ td >
35 < td >
36 < asp:ContentPlaceHolder ID = " ContentPlaceHolder2 "
37 Runat = " server " >
38 </ asp:ContentPlaceHolder >
39 </ td >
40 </ tr >
41 < tr >
42 < td colspan = " 2 " >
43 Copyright 2008 - My Company
44 </ td >
45 </ tr >
46 </ table >
47 </ form >
48 </ body >
49 </ html >
 在Master 页面 设置  Label1.Text = System.Guid.NewGuid().ToString();

引用页面:
 
  
1 <% @ Page Language = " C# " MasterPageFile = " ~/Listing 05-08.master " Title = " Untitled Page " %>
2
3 < script runat = " server " >
4
5 protected void Page_LoadComplete( object sender, EventArgs e)
6 {
7 Label1.Text = (Master.FindControl( " Label1 " ) as Label).Text;
8 Master.FindControl( "" );
9 }
10
11 protected void Button1_Click( object sender, EventArgs e)
12 {
13 Label2.Text = " <b>Hello " + TextBox1.Text + " !</b> " ;
14 }
15 </ script >
16
17 < asp:Content ID = " Content1 " ContentPlaceHolderID = " head " Runat = " Server " >
18 </ asp:Content >
19
20 < asp:Content ID = " Content2 " ContentPlaceHolderId = " ContentPlaceHolder1 "
21 runat = " server " >
22 < b > Your GUID number from the master page is : < br />
23 < asp:Label ID = " Label1 " runat = " server " /></ b >< p >
24 < b > Enter your name: </ b >< br />
25 < asp:Textbox ID = " TextBox1 " runat = " server " />
26 < br />
27 < br />
28 < asp:Button ID = " Button1 " runat = " server " Text = " Submit " OnClick = " Button1_Click " />< br />
29 < br />
30 < asp:Label ID = " Label2 " runat = " server " Font - Bold = " True " />
31 </ asp:Content >
32
33 < asp:Content ID = " Content3 " ContentPlaceHolderId = " ContentPlaceHolder2 " runat = " server " >
34 < asp:Image ID = " Image1 " runat = " server " ImageUrl = " Wrox.gif " />
35 </ asp:Content >
用 Master.FindControl() 的方法找出控件

转载于:https://www.cnblogs.com/qiuweiguo/archive/2011/06/14/2080640.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值