Asp.NET中弹出窗体与父窗体之间的传值
来源:互联网 发布:淘宝做工问题退货规则 编辑:程序博客网 时间:2024/05/02 04:17
经常遇到从弹出窗体与父窗体之间的传值问题,特别是在弹出窗体中的含有GridView控件的传值。在下面的例子中,我们将使用两个表单,父表单在PopupWindowPassValue.aspx中和弹出表单在PopupPage.aspx中;代码分为vb.Net和C#.Net
--- .aspx of parent form ---
<script type="text/javascript">
function OpenPopup() {
window.open("popup.aspx","List","scrollbars=no,resizable=no,width=400,height=280");
return false;
}
</script>
.
.
.
<asp:TextBox ID="txtPopupValue" runat="server" Width="327px"></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="Show List" />
--- .vb of parent.aspx if vb.net is the language ---
If Not IsPostBack Then
Me.Button1.Attributes.Add("onclick", "javascript:return OpenPopup()")
End If
--- .cs of parent.aspx if C#.net is the language ---
if (!IsPostBack) {
this.Button1.Attributes.Add("onclick", "javascript:return OpenPopup()");
}
--- .aspx of popup form ---
<script language="javascript">
function GetRowValue(val)
{
// hardcoded value used to minimize the code.
// ControlID can instead be passed as query string to the popup window
window.opener.document.getElementById("ctl00_ContentPlaceHolder1_TextBox2").value = val;
window.close();
}
</script>
<asp:GridView ID="GridView1" runat="server" DataSourceID="SqlDataSource1">
<Columns>
<asp:TemplateField>
<AlternatingItemTemplate>
<asp:Button ID="btnSelect" runat="server" Text="Select" />
</AlternatingItemTemplate>
<ItemTemplate>
<asp:Button ID="btnSelect" runat="server" Text="Select" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
--- .vb file if vb.net is the language ---
Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e AsSystem.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound
If (e.Row.RowType = DataControlRowType.DataRow) Then
'assuming that the required value column is the second column in gridview
DirectCast(e.Row.FindControl("btnSelect"), Button).Attributes.Add("onclick","javascript:GetRowValue('" & e.Row.Cells(1).Text & "')")
End If
End Sub
--- .cs file if C#.net is the language ---
protected void GridView1_RowDataBound(object sender, System.Web.UI.WebControls.GridViewRowEventArgs e) {
if ((e.Row.RowType == DataControlRowType.DataRow)) {
//assuming that the required value column is the second column in gridview
((Button)e.Row.FindControl("btnSelect")).Attributes.Add("onclick","javascript:GetRowValue('" + e.Row.Cells[1].Text + "')");
}
}
原文连接:http://wiki.asp.net/page.aspx/282/passing-value-from-popup-window-to-parent-form39s-textbox/
demo下载:http://download.csdn.net/source/3572812
- Asp.NET中弹出窗体与父窗体之间的传值
- asp.net子窗体与父窗体之间互操作
- sharepoint 中弹出模式窗体
- 对网页中弹出窗体的一点操作
- ASP.NET中弹出MessageBox的方法
- 在Service中弹出一个窗体
- 父窗体与子窗体之间的相互操作
- C# 子窗体与父窗体之间几种传值的方式
- html 框架中子窗体与父窗体之间的调用
- 父窗体与子窗体之间的调用-使用模态窗体之间传递多个值
- VB.Net 两个窗体之间的传值及修改
- ASP.NET如何在窗体和窗体之间传送数据
- ASP.NET如何在窗体和窗体之间传送数据
- ASP.NET如何在窗体和窗体之间传送数据
- ASP.NET如何在窗体和窗体之间传送数据
- asp.net 父窗体获取子窗体的返回值,对父窗体局部更新(模式化窗口)
- asp.net 父窗体获取子窗体的返回值,对父窗体局部更新(模式化窗口)
- Asp.net 中弹出窗口
- 长连接和短连接
- 用java写二叉树的算法
- C#中如何表示文件相对路径
- 单一职责原则
- phpmail使用方法
- Asp.NET中弹出窗体与父窗体之间的传值
- Android培训班(67)dex文件打开流程
- LRU算法的实现
- JDK环境变量配置
- 给孩子的备忘录——梁继璋给儿子的信
- Tomcat环境变量配置
- c++继承中的内存布局
- poj 2777 Count color
- [CentOs 5.5 X64] CentOS 安裝 Broadcom BCM43225 無線網路卡驅動程式