七道最经典的asp.net页面传值题

第一题:一个Page:PageA.aspx的网页上放有一个TextBox ID为TextBox1和一个Button ID为Button1;
      一个User Control:UcA.ascx的网页上放有一个Label ID为Label1。这个UcA.ascx并拉入到PageA.aspx上。
        在TextBox1输入一个值,并按Button1,然把TextBox1的值传至UcA.ascx并显示于Label1。
        请写代码实现!


第二题:一个Page:PageA.aspx的网页上放有一个TextBox ID 为TextBox1;
      一个User Control:UcA.ascx的网页上放有一个Button ID为Button1和一个Label ID为Label1,这个UcA.ascx并拉  入到PageA.aspx上。
在TextBox1输入一个值,并接UcA.ascx上的Button1,然把TextBox1的值传至UcA.ascx并显示于Label1。
请写代码实现!


第三题:一个User Control:UcA.ascx的网页上放有一个TextBox ID为TextBox1;
      一个Page:PageA.aspx的网页上放有一个Button ID为Button1和一个Label ID为Label1;
      然后把这个UcA.ascx并拉入到PageA.aspx上。
        在UcA.ascx的TextBox1输入一个值,点PageA.aspx上的Button1,然后把TextBox1的值传至PageA.aspx并显示于  Label1上。
请写代码实现!


第四题:一个User Control:UcA.ascx的网页上放有一个TextBox ID为TextBox1和一个Button ID为Button1;
      一个Page:PageA.aspx的网页上放有一个Label ID为Label1;
      然后把这个UcA.ascx拉至PageA.aspx上。
        在UcA.ascx的TextBox1输入一个值,点UCA.ascx上的Button1,然后把TextBox1的值传至PageA.aspx并显示于Label1上。


第五题:一个User Control:UcA.ascx的网页上放有一个TextBox ID为TextBox1;
      一个Page:PageA.aspx的网页上放有一个Button ID为Button1;
      一个User Control:UcB.ascx的网页上放有一个Label ID为Label1;
      然后UcA.ascx和UcB.ascx都拉至PageA.aspx上;
        然后在UcA.ascx的TextBox1输入一个值,点PageA.aspx页面上的Button1,把TextBox1的值传至UcB.ascx的Label1上。
请写代码实现!


第六题:一个User Control:UcA.ascx的网页上放有一个TextBox ID为TextBox1和一个Button ID为Button1;
      一个Page:PageA.aspx;
        一个User Control:UcB.ascx的网页上放有一个Label ID为Label1;
      然后把UcA.ascx和UcB.ascx都拉至PageA.aspx上。
        然后在UcA.ascx的TextBox1输入一个值,点UcA.ascx上的Button1,把TextBox1的值传至UcB.ascx的Label1上。
      请用代码实现!


第七题:一个User Control:UcA.ascx的网页上放有一个TextBox ID为TextBox1;
      一个Page:PageA.aspx;
        一个User Control:UcB.ascx的网页上放有一个Button ID为Button1和一个Label ID为Label1;
      然后把UcA.ascx和UcB.ascx都拉至PageA.aspx上。
        然后在UcA.ascx的TextBox1输入一个值,点UcB.ascx上的Button1,把TextBox1的值传至UcB.ascx的Label1上。
      请用代码实现!

来个全的
用不用属性、委托都可以,下面的有的用了有的没用
IDE:vs2005
第一题
HTML code
   
   
<% @ Page Language = " C# " AutoEventWireup = " true " CodeFile = " PageA.aspx.cs " Inherits = " yuxuanji_PageA " %> <% @ Register Src = " UcA.ascx " TagName = " UcA " TagPrefix = " uca " %> <! DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" > < html xmlns ="http://www.w3.org/1999/xhtml" > < head runat ="server" > < title > 无标题页 </ title > </ head > < body > < form id ="form1" runat ="server" > < div > < table height ="40px" border ="0" align ="center" cellpadding ="0" cellspacing ="0" > < tr > < td > < uca:UcA ID ="UcA1" runat ="server" /> </ td > </ tr > </ table > < table align ="center" cellpadding ="1" cellspacing ="0" > < tr > < asp:TextBox ID ="TextBox1" runat ="server" ></ asp:TextBox ></ tr > < tr > < asp:Button ID ="Button1" runat ="server" OnClick ="Button1_Click" Text ="Button" /></ tr > </ table > </ div > </ form > </ body > </ html >

C# code
   
   
using System; using System.Data; using System.Configuration; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; public partial class yuxuanji_PageA : System.Web.UI.Page { protected void Page_Load( object sender, EventArgs e) { } protected void Button1_Click( object sender, EventArgs e) { Label Label1 = (Label)UcA1.FindControl( " Label1 " ); Label1.Text = TextBox1.Text; } }


HTML code
   
   
<% @ Control Language = " C# " AutoEventWireup = " true " CodeFile = " UcA.ascx.cs " Inherits = " yuxuanji_UcA " %> < asp:Label ID ="Label1" runat ="server" ></ asp:Label >


C# code
   
   
using System; using System.Data; using System.Configuration; using System.Collections; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; public partial class yuxuanji_UcA : System.Web.UI.UserControl { protected void Page_Load( object sender, EventArgs e) { } }



第二题
HTML code
   
   
<% @ Page Language = " C# " AutoEventWireup = " true " CodeFile = " PageA.aspx.cs " Inherits = " yuxuanji_PageA " %> <% @ Register Src = " UcA.ascx " TagName = " UcA " TagPrefix = " uca " %> <! DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" > < html xmlns ="http://www.w3.org/1999/xhtml" > < head runat ="server" > < title > 无标题页 </ title > </ head > < body > < form id ="form1" runat ="server" > < div > < table height ="40px" border ="0" align ="center" cellpadding ="0" cellspacing ="0" > < tr > < td > < asp:TextBox ID ="TextBox1" runat ="server" ></ asp:TextBox > </ td > </ tr > </ table > < table align ="center" cellpadding ="1" cellspacing ="0" > < tr > < td > < uca:UcA ID ="UcA1" runat ="server" /> </ td > </ tr > </ table > </ div > </ form > </ body > </ html >


C# code
   
   
using System; using System.Data; using System.Configuration; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; public partial class yuxuanji_PageA : System.Web.UI.Page { protected void Page_Load( object sender, EventArgs e) { } protected override void OnInit(EventArgs e) { base .OnInit(e); ((Button)UcA1.FindControl( " Button1 " )).Click += new EventHandler(UcA1_Click); // 也可放在Page_Load里 } void UcA1_Click( object sender, EventArgs e) { UcA1.TextOfLabel1 = TextBox1.Text; } }


HTML code
   
   
<% @ Control Language = " C# " AutoEventWireup = " true " CodeFile = " UcA.ascx.cs " Inherits = " yuxuanji_UcA " %> < asp:Label ID ="Label1" runat ="server" ></ asp:Label > < asp:Button ID ="Button1" runat ="server" Text ="Button" />

C# code
   
   
using System; using System.Data; using System.Configuration; using System.Collections; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; public partial class yuxuanji_UcA : System.Web.UI.UserControl { protected void Page_Load( object sender, EventArgs e) { } public string TextOfLabel1 { get { return Label1.Text; } set { Label1.Text = value.ToString(); } } }


第三题
HTML code
   
   
<% @ Page Language = " C# " AutoEventWireup = " true " CodeFile = " PageA.aspx.cs " Inherits = " yuxuanji_PageA " %> <% @ Register Src = " UcA.ascx " TagName = " UcA " TagPrefix = " uca " %> <! DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" > < html xmlns ="http://www.w3.org/1999/xhtml" > < head runat ="server" > < title > 无标题页 </ title > </ head > < body > < form id ="form1" runat ="server" > < div > < table height ="40px" border ="0" align ="center" cellpadding ="0" cellspacing ="0" > < tr > < td > < uca:UcA ID ="UcA1" runat ="server" /> </ td > </ tr > </ table > < table align ="center" cellpadding ="1" cellspacing ="0" > < tr > < td > < asp:Label ID ="Label1" runat ="server" ></ asp:Label >< asp:Button ID ="Button1" runat ="server" Text ="Button" OnClick ="Button1_Click" /> </ td > </ tr > </ table > </ div > </ form > </ body > </ html >

C# code
   
   
using System; using System.Data; using System.Configuration; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; public partial class yuxuanji_PageA : System.Web.UI.Page { protected void Page_Load( object sender, EventArgs e) { } protected void Button1_Click( object sender, EventArgs e) { TextBox TextBox1 = (TextBox)UcA1.FindControl( " TextBox1 " ); Label1.Text = TextBox1.Text; } }


HTML code
   
   
<% @ Control Language = " C# " AutoEventWireup = " true " CodeFile = " UcA.ascx.cs " Inherits = " yuxuanji_UcA " %> < asp:TextBox ID ="TextBox1" runat ="server" ></ asp:TextBox >

C# code
   
   
using System; using System.Data; using System.Configuration; using System.Collections; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; public partial class yuxuanji_UcA : System.Web.UI.UserControl { protected void Page_Load( object sender, EventArgs e) { } }
   
   
第四题
HTML code
        
        
<% @ Page Language = " C# " AutoEventWireup = " true " CodeFile = " PageA.aspx.cs " Inherits = " yuxuanji_PageA " %> <% @ Register Src = " UcA.ascx " TagName = " UcA " TagPrefix = " uca " %> <! DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" > < html xmlns ="http://www.w3.org/1999/xhtml" > < head runat ="server" > < title > 无标题页 </ title > </ head > < body > < form id ="form1" runat ="server" > < div > < table height ="40px" border ="0" align ="center" cellpadding ="0" cellspacing ="0" > < tr > < td > < uca:UcA ID ="UcA1" runat ="server" /> </ td > </ tr > </ table > < table align ="center" cellpadding ="1" cellspacing ="0" > < tr > < td > < asp:Label ID ="Label1" runat ="server" ></ asp:Label > </ td > </ tr > </ table > </ div > </ form > </ body > </ html >


C# code
        
        
using System; using System.Data; using System.Configuration; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; public partial class yuxuanji_PageA : System.Web.UI.Page { protected void Page_Load( object sender, EventArgs e) { } protected override void OnInit(EventArgs e) { base .OnInit(e); // ((Button)UcA1.FindControl("Button1")).Click += new EventHandler(UcA1_Click); UcA1.SetButton1 = new EventHandler(UcA1_Click); } void UcA1_Click( object sender, EventArgs e) { TextBox TextBox1 = (TextBox)UcA1.FindControl( " TextBox1 " ); Label1.Text = TextBox1.Text; } }


HTML code
        
        
<% @ Control Language = " C# " AutoEventWireup = " true " CodeFile = " UcA.ascx.cs " Inherits = " yuxuanji_UcA " %> < asp:TextBox ID ="TextBox1" runat ="server" ></ asp:TextBox >< asp:Button ID ="Button1" runat ="server" Text ="Button" />

C# code
        
        
using System; using System.Data; using System.Configuration; using System.Collections; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; public partial class yuxuanji_UcA : System.Web.UI.UserControl { protected void Page_Load( object sender, EventArgs e) { } public EventHandler SetButton1 { set { this .Button1.Click += value; } } }


第五题
HTML code
        
        
<% @ Page Language = " C# " AutoEventWireup = " true " CodeFile = " PageA.aspx.cs " Inherits = " yuxuanji_PageA " %> <% @ Register Src = " UcA.ascx " TagName = " UcA " TagPrefix = " uca " %> <% @ Register Src = " UcB.ascx " TagName = " UcB " TagPrefix = " uca " %> <! DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" > < html xmlns ="http://www.w3.org/1999/xhtml" > < head runat ="server" > < title > 无标题页 </ title > </ head > < body > < form id ="form1" runat ="server" > < div > < table height ="40px" border ="0" align ="center" cellpadding ="0" cellspacing ="0" > < tr > < td > < uca:UcA ID ="UcA1" runat ="server" /> </ td > </ tr > < tr > < td > < uca:UcB ID ="UcB1" runat ="server" /> </ td > </ tr > </ table > < table align ="center" cellpadding ="1" cellspacing ="0" > < tr > < td > < asp:Button ID ="Button1" runat ="server" Text ="Button" OnClick ="Button1_Click" /> </ td > </ tr > </ table > </ div > </ form > </ body > </ html >


C# code
        
        
using System; using System.Data; using System.Configuration; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; public partial class yuxuanji_PageA : System.Web.UI.Page { protected void Page_Load( object sender, EventArgs e) { } protected void Button1_Click( object sender, EventArgs e) { TextBox TextBox1 = (TextBox)UcA1.FindControl( " TextBox1 " ); Label Label1 = (Label)UcB1.FindControl( " Label1 " ); Label1.Text = TextBox1.Text; } }


HTML code
        
        
<% @ Control Language = " C# " AutoEventWireup = " true " CodeFile = " UcA.ascx.cs " Inherits = " yuxuanji_UcA " %> < asp:TextBox ID ="TextBox1" runat ="server" ></ asp:TextBox >

C# code
        
        
using System; using System.Data; using System.Configuration; using System.Collections; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; public partial class yuxuanji_UcA : System.Web.UI.UserControl { protected void Page_Load( object sender, EventArgs e) { } }


HTML code
        
        
<% @ Control Language = " C# " AutoEventWireup = " true " CodeFile = " UcB.ascx.cs " Inherits = " yuxuanji_UcB " %> < asp:Label ID ="Label1" runat ="server" ></ asp:Label >

C# code
        
        
using System; using System.Data; using System.Configuration; using System.Collections; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; public partial class yuxuanji_UcB : System.Web.UI.UserControl { protected void Page_Load( object sender, EventArgs e) { } }
第六题 
HTML code
           
           
<% @ Page Language = " C# " AutoEventWireup = " true " CodeFile = " PageA.aspx.cs " Inherits = " yuxuanji_PageA " %> <% @ Register Src = " UcA.ascx " TagName = " UcA " TagPrefix = " uca " %> <% @ Register Src = " UcB.ascx " TagName = " UcB " TagPrefix = " uca " %> <! DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" > < html xmlns ="http://www.w3.org/1999/xhtml" > < head runat ="server" > < title > 无标题页 </ title > </ head > < body > < form id ="form1" runat ="server" > < div > < table height ="40px" border ="0" align ="center" cellpadding ="0" cellspacing ="0" > < tr > < td > < uca:UcA ID ="UcA1" runat ="server" /> </ td > </ tr > < tr > < td > < uca:UcB ID ="UcB1" runat ="server" /> </ td > </ tr > </ table > < table align ="center" cellpadding ="1" cellspacing ="0" > < tr > < td > </ td > </ tr > </ table > </ div > </ form > </ body > </ html >

C# code
           
           
using System; using System.Data; using System.Configuration; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; public partial class yuxuanji_PageA : System.Web.UI.Page { protected void Page_Load( object sender, EventArgs e) { } protected override void OnInit(EventArgs e) { base .OnInit(e); ((Button)UcA1.FindControl( " Button1 " )).Click += new EventHandler(UcA1_Click); } void UcA1_Click( object sender, EventArgs e) { TextBox TextBox1 = (TextBox)UcA1.FindControl( " TextBox1 " ); Label Label1 = (Label)UcB1.FindControl( " Label1 " ); Label1.Text = TextBox1.Text; } }


HTML code
           
           
<% @ Control Language = " C# " AutoEventWireup = " true " CodeFile = " UcA.ascx.cs " Inherits = " yuxuanji_UcA " %> < asp:TextBox ID ="TextBox1" runat ="server" ></ asp:TextBox >< br /> < asp:Button ID ="Button1" runat ="server" Text ="Button" />

C# code
           
           
using System; using System.Data; using System.Configuration; using System.Collections; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; public partial class yuxuanji_UcA : System.Web.UI.UserControl { protected void Page_Load( object sender, EventArgs e) { } }


HTML code
           
           
<% @ Control Language = " C# " AutoEventWireup = " true " CodeFile = " UcB.ascx.cs " Inherits = " yuxuanji_UcB " %> < asp:Label ID ="Label1" runat ="server" ></ asp:Label >

C# code
           
           
using System; using System.Data; using System.Configuration; using System.Collections; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; public partial class yuxuanji_UcB : System.Web.UI.UserControl { protected void Page_Load( object sender, EventArgs e) { } }



第七题
HTML code
           
           
<% @ Page Language = " C# " AutoEventWireup = " true " CodeFile = " PageA.aspx.cs " Inherits = " yuxuanji_PageA " %> <% @ Register Src = " UcA.ascx " TagName = " UcA " TagPrefix = " uca " %> <% @ Register Src = " UcB.ascx " TagName = " UcB " TagPrefix = " uca " %> <! DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" > < html xmlns ="http://www.w3.org/1999/xhtml" > < head runat ="server" > < title > 无标题页 </ title > </ head > < body > < form id ="form1" runat ="server" > < div > < table height ="40px" border ="0" align ="center" cellpadding ="0" cellspacing ="0" > < tr > < td > < uca:UcA ID ="UcA1" runat ="server" /> </ td > </ tr > < tr > < td > < uca:UcB ID ="UcB1" runat ="server" /> </ td > </ tr > </ table > < table align ="center" cellpadding ="1" cellspacing ="0" > < tr > < td > </ td > </ tr > </ table > </ div > </ form > </ body > </ html >


C# code
           
           
using System; using System.Data; using System.Configuration; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; public partial class yuxuanji_PageA : System.Web.UI.Page { protected void Page_Load( object sender, EventArgs e) { } protected override void OnInit(EventArgs e) { base .OnInit(e); ((Button)UcB1.FindControl( " Button1 " )).Click += new EventHandler(UcB1_Click); } void UcB1_Click( object sender, EventArgs e) { TextBox TextBox1 = (TextBox)UcA1.FindControl( " TextBox1 " ); Label Label1 = (Label)UcB1.FindControl( " Label1 " ); Label1.Text = TextBox1.Text; } }


HTML code
           
           
<% @ Control Language = " C# " AutoEventWireup = " true " CodeFile = " UcA.ascx.cs " Inherits = " yuxuanji_UcA " %> < asp:TextBox ID ="TextBox1" runat ="server" ></ asp:TextBox >

C# code
           
           
using System; using System.Data; using System.Configuration; using System.Collections; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; public partial class yuxuanji_UcA : System.Web.UI.UserControl { protected void Page_Load( object sender, EventArgs e) { } }


HTML code
           
           
<% @ Control Language = " C# " AutoEventWireup = " true " CodeFile = " UcB.ascx.cs " Inherits = " yuxuanji_UcB " %> < asp:Button ID ="Button1" runat ="server" Text ="Button" />< br /> < asp:Label ID ="Label1" runat ="server" ></ asp:Label >


C# code
           
           
using System; using System.Data; using System.Configuration; using System.Collections; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; public partial class yuxuanji_UcB : System.Web.UI.UserControl { protected void Page_Load( object sender, EventArgs e) { } }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值