.NET中利用js让子窗体向父页面传值的实现方法
程序员文章站
2024-03-04 22:18:30
子页面c#后台代码:复制代码 代码如下:/// /// 将设置好的...
子页面c#后台代码:
复制代码 代码如下:
/// <summary>
/// 将设置好的值赋给父页面
/// </summary>
/// <param name="count">需要传递的值</param>
void setvaluetoparentpage(int count, string strpersons)
{
stringbuilder jsstr = new stringbuilder();
jsstr.append(" var retvalue = new object();");
if (count == 0)
{
jsstr.appendformat("retvalue = null;");
}
else
{
jsstr.appendformat("retvalue.nums='{0}';", count);
jsstr.appendformat("retvalue.names='{0}';", strpersons);
}
jsstr.append("window.returnvalue = retvalue;window.close();");
clientscript.registerstartupscript(gettype(), "close", jsstr.tostring(), true);
}
父页面前台js:
复制代码 代码如下:
function openperchoose(url) {
var openobj = window;
if (typeof (window.dialogarguments) == "object") {
openobj = window.dialogarguments;
}
var returnvalue = showpopwin(url, 800, 600, openobj);
if (returnvalue != null) {
document.getelementbyid("<%=txtqualifiednums.clientid %>").value = returnvalue.nums;
}
}
复制代码 代码如下:
//弹出窗口
function showpopwin(url, width, height, returnfunc) {
width = parseint(width) + 30;
height = parseint(height) + 30;
return window.showmodaldialog(url + "&datetime=" + gettime(), document, "dialogwidth:" + width + "px;dialogheight:" + height + "px;help:0;status:0;scroll:auto;center:1;resizable:1;");
}
<th style="width: 100px;">
培训合格人数:
</th>
<td style="width: 50px;">
<asp:textbox id="txtqualifiednums" runat="server" width="50px" readonly="true"></asp:textbox>
</td>