如何将子aspx的字符串值传递给父aspx文本框 [英] how to pass string value of child aspx to the parent aspx text box
问题描述
您好我将子aspx页面与父aspx页面链接。当我点击父aspx页面中的按钮时,子aspx页面打开。当我单击子aspx页面中的确定按钮时,它已被关闭没有问题,现在我想将子字符串值从子aspx页面(代码隐藏)传递到父aspx页面文本框
怎么可能?
父页面.aspx
< span class =code-keyword> protected void btn_Click( object sender,ImageClickEventArgs e )
{
session [value] = value.tosting();
}
child page.aspx
string empid = ;
受保护 void Page_Load( object sender,EventArgs e)
{
if (会话[ value]。ToString()!= )
{
empid =会话[ value]。ToString();
label.text = empid.tostring();
}
}
您好,试试这个代码..
基于javascript的工作....
父页面:
<%@ Page 语言 = C# AutoEventWireup = true CodeBehind = WebForm1.aspx.cs 继承 = WebApplication1.WebForm1 %>
< !DOCTYPE html >
< < span class =code-leadattribute> html xmlns = http://www.w3.org/1999/xhtml >
< head runat = server < span class =code-keyword>>
< t itle > < / title >
< script src = < span class =code-keyword> jquery.js.js > < / / span> script >
< script type = text / javascript >
var openchild = function ()
{
window .open(' childpage.aspx',' popup_window',' width = 300,height = 100,left = 100,top = 100,resizable = yes');
return false ;
}
< / script >
< / head >
< 正文 >
< 表格 id = form1 runat = server >
< table 跨度>>
< tr >
< td > 父文本框< / td >
< td >
< asp: TextBox ID = txtparent runat = serve r > < / asp :TextBox > < / td >
< / tr >
< tr >
< ; td colspan < span class =code-keyword> = 2 对齐 = center >
< asp:Button ID = btnSearch OnClientClick = return openchild() runat = server 文本 = open child / > < / td >
< / tr >
< / table >
< / form >
< / body >
< / html >
__________________________________________________________________________________________________
子页面
<%@ Page 语言 = C# AutoEventWireup = true CodeBehind = childpage.aspx.cs 继承 = WebApplication1.childpage %>
< !DOCTYPEhtml > script type = text / javascript >
< html xmlns = http://www.w3.org/1999/ xhtml >
< head runat = server >
< title > < / title >
<
var closechild = function (){
var value = document .getElementById(' txtchild'跨度>)值;
window .opener。 document 。 getElementById(' txtparent')。value = value;
window .close();
返回 false ;}
< / script >
< / head >
< body >
< 表格 id = form1 runat = 服务器 >
< div >
< span class =code-keyword>< table >
< tr >
< td > 子文本框< / td >
< td >
< asp:TextBox ID = txtchild runat = server > < / asp:TextBox > < / td >
< / tr >
< tr >
< td colspan = 2 align = center >
< asp:按钮 ID = btnclose OnClientClick = return closechild() runat = server 文字 = close child / > < / td >
< / tr >
< / table >
< / div >
< / form >
< / body >
< / html >
< blockquote>检查以下链接:
链接1 [ ^ ]
Link 2 [ ^ ]
Link 3 [ ^ ]
Link 4 [ ^ ]
Link 5 [ ^ ]
Link 6 [ ^ ]
Hi i am linked the child aspx page with parent aspx page. when i click the button in parent aspx page the child aspx page opening. and when i click the OK button in the child aspx page, it has been closed no problem and now i want to pass the string value from the child aspx page (code behind) to parent aspx page textbox
How is possible?
Parent page.aspx
protected void btn_Click(object sender, ImageClickEventArgs e) {
session["value"]=value.tosting(); }
child page.aspx
string empid="";
protected void Page_Load(object sender, EventArgs e) { if (Session["value"].ToString() != "") { empid = Session["value"].ToString(); label.text=empid.tostring(); }
}
Hi, Try this code..
its working based on javascript....
Parent page :
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication1.WebForm1" %> <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> <script src="jquery.js.js"></script> <script type="text/javascript"> var openchild = function () { window.open('childpage.aspx', 'popup_window', 'width=300,height=100,left=100,top=100,resizable=yes'); return false; } </script> </head> <body> <form id="form1" runat="server"> <table> <tr> <td>parent textbox</td> <td> <asp:TextBox ID="txtparent" runat="server"></asp:TextBox></td> </tr> <tr> <td colspan="2" align="center"> <asp:Button ID="btnSearch" OnClientClick="return openchild()" runat="server" Text="open child" /></td> </tr> </table> </form> </body> </html>
__________________________________________________________________________________________________
child page
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="childpage.aspx.cs" Inherits="WebApplication1.childpage" %> <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> <script type="text/javascript"> var closechild = function () { var value = document.getElementById('txtchild').value; window.opener.document. getElementById('txtparent').value = value; window.close(); return false;} </script> </head> <body> <form id="form1" runat="server"> <div> <table> <tr> <td>child textbox</td> <td> <asp:TextBox ID="txtchild" runat="server"></asp:TextBox></td> </tr> <tr> <td colspan="2" align="center"> <asp:Button ID="btnclose" OnClientClick="return closechild()" runat="server" Text="close child" /></td> </tr> </table> </div> </form> </body> </html>
Check these links:
Link 1[^]
Link 2[^]
Link 3[^]
Link 4[^]
Link 5[^]
Link 6[^]
这篇关于如何将子aspx的字符串值传递给父aspx文本框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!