关于子窗体传值给父窗体应该怎么传。我很菜。各位帮下忙!
我父窗体中点button的时候触发js的方法,把要传值控件的id传给子窗体 function newWindow(id)
{
window.open("ceshi.aspx?id="+id+"","sub","HEIGHT=300,WIDTH=300");
}我子窗体中只有一个Textbox1和一个button1,我想在点button的时候把Textbox1的值传回给要传值的控件
应该怎么写,在后台和前台分别应该怎么写,各位用代码告诉我一下,在线等,全分送。谢谢!
我父窗体中点button的时候触发js的方法,把要传值控件的id传给子窗体 function newWindow(id)
{
window.open("ceshi.aspx?id="+id+"","sub","HEIGHT=300,WIDTH=300");
}我子窗体中只有一个Textbox1和一个button1,我想在点button的时候把Textbox1的值传回给要传值的控件
应该怎么写,在后台和前台分别应该怎么写,各位用代码告诉我一下,在线等,全分送。谢谢!
这个东西 当你在父窗体单击button后 在子窗体写一个js
windows.returnvalue=textbox1.text(假设具体取这个值,要看你的子窗体了)
然后把父窗体的代码改为
var testvalue=window.open("ceshi.aspx?id="+id+"","sub","HEIGHT=300,WIDTH=300");
然后父窗体就可以得到子窗体的值了
如果要传给其他页面。就要用到页面传值。或者上楼提到的session 也是可以的
或者
window.open("ceshi.aspx?id="+id+"","sub","HEIGHT=300,WIDTH=300");在 父页面 得到ID 的值用 SESSION 大材小用叻
学到一点~
sb.Append("window.parent.opener.document.getElementById('父窗体控件的id').value='" Textbox1.Text + "';window.close();");
Type t = this.GetType();
ClientScriptManager cs = Page.ClientScript;
cs.RegisterStartupScript(t, "", sb.ToString(), true);
父窗體:
var arr =window.showModalDialog('../TestAjax/slectZRren.aspx?type='+type,'請選擇責任人','dialogWidth:500px;dialogHeight:500px;status:no;help:no');
if (arr!= null)
{
var ss;
document.getElementById(txtFZRen).value = ss[0];
}
子窗體:
var lab2 = document.getElementById("TextBox1");
window.returnValue = lab2;
window.close();
opener.document.getElementById('父窗口接受参数控件的id').value=document.getElementById('TextBox1');opener指向父窗口
父窗体:
function newWindow(id)
{
window.open("ceshi.aspx?id="+id+"","sub","HEIGHT=300,WIDTH=300");
}
子窗体:function Return()
{
window.parent.opener.document.getElementById('<%=TextBox1.ClientID %>').value=document.getElementById('<%=TextBox1.ClientID %>').value ;
window.close();
}
this.Button2.Attributes.Add("onclick", "Return()");
2)通過子窗体傳回值給父窗体
父窗体:
function newWindow(id)
{
var strReturn=window.open("ceshi.aspx?id="+id+"","sub","HEIGHT=300,WIDTH=300");
}
子窗体:
function Return()
{
windows.returnvalue = document.getElementById('<%=TextBox1.ClientID %>').value ;
window.close();
}
function newWindow(id)
{
var strReturn=window.showModalDialog("ceshi.aspx?id="+id+","sub","dialogTop:200px;dialogLeft:300px");
document.getElementById('父窗体控件id').value=strReturn;
}ceshi.aspx页面(子窗口)
在<head>后最好添加一个<base target="_self" />
js代码:
function setstr()
{
var strResult=document.getElementById("Textbox1").value;
window.returnValue=strResult;
window.close();
}cs:
protected void ImageButton2_Click(object sender, EventArgs e)
{
string str = "<script type='text/javascript'>setstr();</script>";
Page.ClientScript.RegisterStartupScript(this.GetType(), "1", str);
}
用opener
如:17楼。
看来是白做,白写和白录影片!
另外,csdn上传出了问题,几次向csdn问题反映,都没有人理,也没有回音!