子页面赋值给父页面的控件方法

在父页面Parent.aspx点击弹出第二个页面,将会弹出Child.aspx子页面,在子页面中输入需要传入到Parent.aspx的值点击确认,则可以把Child.aspx子页面输入的值传到Parent.aspx上的控件上。
Parent.aspx的HTML为:
None.gif<%@ Page language="c#" Codebehind="Parent.aspx.cs" AutoEventWireup="false" Inherits="TestToParent.WebForm1" %>
None.gif
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
None.gif
<HTML>
None.gif    
<HEAD>
None.gif        
<title>WebForm1</title>
None.gif        
<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
None.gif        
<meta name="CODE_LANGUAGE" Content="C#">
None.gif        
<meta name="vs_defaultClientScript" content="JavaScript">
None.gif        
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
None.gif        
<script language="javascript">
None.gif
None.gif
// ------------------弹出window.open窗口--------------------
None.gif
function openwin(fileName,type,window_width,window_height,property)
ExpandedBlockStart.gifContractedBlock.gif
dot.gif
InBlock.gif    var top  
= (window.screen.availHeight-window_height)/2;
InBlock.gif    var left 
= (window.screen.availWidth-window_width)/2;
InBlock.gif    var newwindow;
InBlock.gif    
if (window_width=="" && window_height=="")
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif       
if (type=="0")
ExpandedSubBlockStart.gifContractedSubBlock.gif       
dot.gif{
InBlock.gif           newwindow
=window.open(fileName,"","left="+left+",top="+top+","+property);
ExpandedSubBlockEnd.gif       }

InBlock.gif       
else
ExpandedSubBlockStart.gifContractedSubBlock.gif       
dot.gif{
InBlock.gif           newwindow
=window.open(fileName,"","left=0,top=0,"+property);
ExpandedSubBlockEnd.gif       }

ExpandedSubBlockEnd.gif    }

InBlock.gif    
else
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif    
if (type=="0")
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        newwindow
=window.open(fileName,"","left=0,top=0,height="+window_height+",width="+window_width+","+property);
ExpandedSubBlockEnd.gif    }

InBlock.gif    
else
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        newwindow
=window.open(fileName,"","left="+left+",top="+top+",height="+window_height+",width="+window_width+","+property);
ExpandedSubBlockEnd.gif    }

InBlock.gif       
ExpandedSubBlockEnd.gif    }

InBlock.gif    
return newwindow;
ExpandedBlockEnd.gif}

None.gif
None.giffunction openwinsimp(fileName,window_width,window_height)
ExpandedBlockStart.gifContractedBlock.gif
dot.gif
InBlock.gif
InBlock.gif    
//alert(fileName);
InBlock.gif
    var newwindow=openwin(fileName,'1',window_width,window_height,'resizable=no,scrollbars=auto,status=yes,toolbar=no,menubar=no,location=no');
InBlock.gif    newwindow.focus();
InBlock.gif    
InBlock.gif    
return newwindow;
ExpandedBlockEnd.gif}

None.gif
None.gif        
</script>
None.gif        
<script>
None.gif        function getid()
ExpandedBlockStart.gifContractedBlock.gif        
dot.gif{
InBlock.gif
InBlock.gif          var id 
= new String(window.location.href);
InBlock.gif          
//alert(id);
InBlock.gif

InBlock.gif            
if( id.indexOf("id="1==-1 )
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif              id
=-1;
InBlock.gif             
InBlock.gif
ExpandedSubBlockEnd.gif            }

InBlock.gif            
else
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif               
InBlock.gif                id 
= parseInt( id.substr( id.indexOf("id="1+ 3 ) );
ExpandedSubBlockEnd.gif            }

InBlock.gif           
// alert(id);
InBlock.gif
             return id;
InBlock.gif             
InBlock.gif           
ExpandedBlockEnd.gif          }

None.gif          
None.gif          
None.gif        
</script>
None.gif    
</HEAD>
None.gif    
<body MS_POSITIONING="GridLayout">
None.gif        
<form id="Form1" method="post" runat="server">
None.gif            
<a href="#" onclick="openwinsimp('./Child.aspx?id='+getid()+'&amp;type=d1&amp;ctrl1ID=txt_Child',1024,768)">
None.gif                弹出一个页面
</a>
None.gif            
<asp:TextBox id="txt_Child" style="Z-INDEX: 101; LEFT: 232px; POSITION: absolute; TOP: 80px"
None.gif                runat
="server"></asp:TextBox>
None.gif            
<asp:Label id="Label1" style="Z-INDEX: 102; LEFT: 96px; POSITION: absolute; TOP: 32px" runat="server">第一个页面</asp:Label>
None.gif            
<asp:Label id="Label2" style="Z-INDEX: 103; LEFT: 40px; POSITION: absolute; TOP: 88px" runat="server">你在第二个页面输入的是:</asp:Label>
None.gif        
</form>
None.gif    
</body>
None.gif
</HTML>
None.gif

预览如下:

0528.JPG

None.gif<%@ Page language="c#" Codebehind="Child.aspx.cs" AutoEventWireup="false" Inherits="TestToParent.WebForm2" %>
None.gif
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
None.gif
<HTML>
None.gif    
<HEAD>
None.gif        
<title>WebForm2</title>
None.gif        
<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
None.gif        
<meta name="CODE_LANGUAGE" Content="C#">
None.gif        
<meta name="vs_defaultClientScript" content="JavaScript">
None.gif        
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
None.gif    
</HEAD>
None.gif    
<body MS_POSITIONING="GridLayout">
None.gif        
<form id="Form1" method="post" runat="server">
None.gif            
<FONT face="宋体">
None.gif                
<asp:Button id="Button1" style="Z-INDEX: 101; LEFT: 120px; POSITION: absolute; TOP: 128px" runat="server"
None.gif                    Text
="Button"></asp:Button>
None.gif                
<asp:TextBox id="TextBox1" style="Z-INDEX: 102; LEFT: 96px; POSITION: absolute; TOP: 88px" runat="server"></asp:TextBox>
None.gif                
<asp:Label id="Label1" style="Z-INDEX: 103; LEFT: 0px; POSITION: absolute; TOP: 96px" runat="server">第二个页面</asp:Label></FONT>
None.gif        
</form>
None.gif    
</body>
None.gif
</HTML>
None.gif

 

.CS代码:

None.gifprivate void Page_Load(object sender, System.EventArgs e)
ExpandedBlockStart.gifContractedBlock.gif        
dot.gif{
InBlock.gif            
// 在此处放置用户代码以初始化页面
InBlock.gif
            if (Request.Params["ctrl1ID"!= null)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                ViewState[
"ctrl1ID"= Request.Params["ctrl1ID"].Trim();
InBlock.gif
ExpandedSubBlockEnd.gif            }

ExpandedBlockEnd.gif        }

None.gif
ContractedBlock.gifExpandedBlockStart.gif        
Web 窗体设计器生成的代码#region Web 窗体设计器生成的代码
InBlock.gif        
override protected void OnInit(EventArgs e)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
//
InBlock.gif            
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
InBlock.gif            
//
InBlock.gif
            InitializeComponent();
InBlock.gif            
base.OnInit(e);
ExpandedSubBlockEnd.gif        }

InBlock.gif        
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
InBlock.gif        
/// 此方法的内容。
ExpandedSubBlockEnd.gif        
/// </summary>

InBlock.gif        private void InitializeComponent()
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{    
InBlock.gif            
this.Button1.Click += new System.EventHandler(this.Button1_Click);
InBlock.gif            
this.Load += new System.EventHandler(this.Page_Load);
InBlock.gif
ExpandedSubBlockEnd.gif        }

ExpandedBlockEnd.gif        
#endregion

None.gif
ExpandedBlockStart.gifContractedBlock.gif        
/**//// <summary>
InBlock.gif        
/// 生成script脚本,完成对父窗口控件的赋值
InBlock.gif        
/// </summary>
InBlock.gif        
/// <param name="value1">控件1的值</param>
InBlock.gif        
/// <param name="value2">控件2的值</param>
ExpandedBlockEnd.gif        
/// <returns></returns>

None.gif        private string MakeScriptStr(string text)
ExpandedBlockStart.gifContractedBlock.gif        
dot.gif{
InBlock.gif
InBlock.gif            
//value= "  [" + value + "]";
InBlock.gif
            string result = "<script>";
InBlock.gif
InBlock.gif            result 
+= "window.opener.document.all('" + ViewState["ctrl1ID"+ "',0).value='" + text + "';";
InBlock.gif            result 
+= "window.close();";
InBlock.gif            result 
+= "</script>";
InBlock.gif
InBlock.gif            
return result;
ExpandedBlockEnd.gif        }

None.gif        
private void Button1_Click(object sender, System.EventArgs e)
ExpandedBlockStart.gifContractedBlock.gif        
dot.gif{
InBlock.gif            
string strScript = this.MakeScriptStr(this.TextBox1.Text);
InBlock.gif            Page.RegisterStartupScript(
"return1", strScript);
InBlock.gif        
ExpandedBlockEnd.gif        }

转载于:https://www.cnblogs.com/hzuIT/articles/761310.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值