通过TabPanel在Parent中传递子值
Passing child values in Parent with TabPanel
我有问题的脚本传递值从孩子到父母与tabpanel(控制器)。在这个选项卡中有一个文本框。当我试图传递TabPanel内的值时,它不起作用。当我移开面板时,它可以工作。
这里的html脚本来自
Parent.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<%@ Register assembly="AjaxControlToolkit" namespace="AjaxControlToolkit" tagprefix="cc1" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="Form1" runat="server">
<cc1:TabContainer ID="TabContainer1" runat="server" ActiveTabIndex="0">
<cc1:TabPanel runat="server" HeaderText="TabPanel1" ID="TabPanel1">
<HeaderTemplate>
TabPanel1<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
</HeaderTemplate>
<ContentTemplate>
<div>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<br />
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
<br />
<asp:Button ID="button1" runat="server" OnClick="button1_Click" Text="Button" />
</div>
</ContentTemplate>
</cc1:TabPanel>
<cc1:TabPanel ID="TabPanel2" runat="server" HeaderText="TabPanel2">
</cc1:TabPanel>
</cc1:TabContainer>
</form>
</body>
</html>
这是子元素和Javascript
child.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Child.aspx.cs" Inherits="Child" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="Initialtest" runat="server"></asp:TextBox>
<br />
<asp:TextBox ID="Initialtest2" runat="server"></asp:TextBox>
<br />
<%--<input type="button" value="Select" onclick="SetName();" />--%>
<asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />
</div>
<script type="text/javascript">
function SetName() {
if (window.opener != null && !window.opener.closed) {
var txtName = window.opener.document.getElementById("TextBox1");
txtName.value = document.getElementById("Initialtest").value;
var txtName1 = window.opener.document.getElementById("TextBox2");
txtName1.value = document.getElementById("Initialtest2").value;
}
alert("test");
window.close();
}
</script>
</form>
</body>
</html>
child.aspx.cs(后面的代码)
public partial class Child : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
//protected void Button1_Click(object sender, EventArgs e)
//{
// //
// Button1.Attributes.Add("onclick", "javascript:SetName();");
//}
protected void Button1_Click(object sender, EventArgs e)
{
Page.ClientScript.RegisterStartupScript(this.GetType(), "CallMyFunction", "SetName()", true);
}
}
子场景必须将值传递给TabPanel中的textbox1。希望有人能帮我解决这个问题。
好了,我解决了这个问题。
<script type="text/javascript">
function SetName() {
if (window.opener != null && !window.opener.closed) {
var txtName = window.opener.document.getElementById("TextBox1");
txtName.value = document.getElementById("Initialtest").value;
var txtName1 = window.opener.document.getElementById("TextBox2");
txtName1.value = document.getElementById("Initialtest2").value;
}
alert("test");
window.close();
}
</script>
相关文章:
- jQuery parent() in table
- iFrame parent node
- Javascript TypeError:$(..)parent不是函数
- parent和iframe中的Bootstrap.js文件
- 如何捕获jqueryDialog和Parent之间的交互
- 如何从DOM(KnockoutJS)中删除$data、$parent等
- 在angular中使用$parent是一种好的做法吗
- 从 Childe 到 Parent ASP 的变量
- this.constructor.apply vs this.parent.apply
- 在JQuery中使用parent()和children()方法的缺点
- 如何在jquery中创建函数和parent.function
- jQuery parent或parents以获取表th标记中的数据属性
- Window.parent and Window.top returning null
- jQuery:如何正确选择parent.prev
- Parent() UL of div
- positon元素相对于JS中的parent.part容器?没有绝对/固定的定位
- 脏表单 - 如何忽略在parent.window.location.href上弹出的脏表单
- 从iframe调用Parent函数,然后更新iframe表单值
- 创建一个类似datatables.net的表示例,其中包含parent/child和+/-响应按钮
- 通过TabPanel在Parent中传递子值