日期:2014-05-18  浏览次数:20363 次

asp.net 2.0 跨页面传值,在线等...
把a.aspx中textbox1.text值传到b.aspx中,然后传回b.aspx中datagrid中选中行的数据

------解决方案--------------------
用postbackurl
------解决方案--------------------
http://dev.yesky.com/msdn/301/2060301.shtml
------解决方案--------------------
postbackurl

自己查msdn,上面有
------解决方案--------------------
a中一定要有提交控件,比如BUTTON,设置它的postbackurl属性为b页面
在b中就可以通过:
TextBox textbox1 = (TextBox)Page.PreviousPage.FindControl( "textbox1 ");
获取a中的文本框,当然其他控件也能获取
------解决方案--------------------
这叫跨页面提交,2005的新特性,postbackurl,搜索一下吧
------解决方案--------------------
在class page中有一個新的property叫PreviousPage他在跨頁面post起到了很關鍵的作用

jj.aspx

<%@ page Language= "C# " CodeFile= "jj.aspx.cs " Inherits= "jj " %> <html> <head id== "Head1 " runat= "server "> <title> jj </title> </head> <body> <form id= "form1 " runat= "server "> <asp:TextBox Runat= "server " ID= "txtJJ " /> <asp:Button Runat= "server " ID= "btnCallToMYM " Text=Submit PostBackUrl= "~/mm.aspx "/> </form> </body> </html>


mm.aspx

<%@ page Language= "C# " CodeFile= "mm.aspx.cs " Inherits= "mm " %> <!--此処多留意--> <%@ PreviousPageType VirtualPath= "~/jj.aspx " %> <html> <head id== "Head1 " runat= "server "> <title> jj </title> </head> <body> <form id= "form1 " runat= "server "> <asp:Label Runat= "server " ID= "txtJJValue " /> </form> </body> </html> mm.aspx.csvoid Page_load(object sender EventArgs e){TextBox txtPostFromJJ=(TextBox)this.PreviousPage.FindControl( "txtJJ ");txtJJValue.Text=txtPostFromJJ.Text;}
如果用户不是通过jj.aspx请求mm.aspx怎么办 我们能使用IsCrossPagePostBack属性来进行判断

mm.aspx.csvoid Page_load(object sender EventArgs e){ if(IsCrossPagePostBack) { TextBox txtPostFromJJ=(TextBox)this.PreviousPage.FindControl( "txtJJ "); txtJJValue.Text=txtPostFromJJ.Text; } else { Response.Redirect( "jj.aspx "); }