ASP.NET 窗体间传值的方法
程序员文章站
2024-02-28 22:10:52
假设parentform.aspx 页面上有textbox1文本框和open按钮点击open按钮弹出subform.aspx,subform.aspx页面上有textbox...
假设parentform.aspx 页面上有textbox1文本框和open按钮
点击open按钮弹出subform.aspx,subform.aspx页面上有textbox1文本框和close按钮
点击close按钮关闭subform.aspx页面,并把子页面subform.aspx文本框的值显示到父页面parentform.aspx 的文本框上。
父窗体前台代码:
<script type="text/javascript">
function opensubform(ret) {
var strpath = "subform.aspx"
var nheight = 500
var nwidth = 500
var feature
feature = "height= " + nheight + ",width=" + nwidth + ",top=30,left=30";
feature += ",dependent=yes,location=no,resizable=yes,scrollbars=yes,status=yes,toolbar=no;";
window.open(strpath+"?ret_form=form1&ret_value="+ret,'subform',feature).focus();
return false;
}
</script>
父窗体后台代码:
private void page_load(object sender, system.eventargs e)
{
// ページを初期化するユーザー コードをここに挿入します
this.button1.attributes.add("onclick","return opensubform('textbox1');");
}
子窗体后台代码:
private void button1_click(object sender, system.eventargs e)
{
string strscript =string.empty;
string strretform = string.empty;
string strretvalue=string.empty;
strretform=request.params["ret_form"];
strretvalue=request.params["ret_value"];
if (strretform == string.empty)
{
strretform= "document.forms[0]";
}
strscript = "<script language=javascript>";
strscript += "window.opener." + strretform;
strscript += "." + strretvalue + ".value='" + this.textbox1.text.trim() + "';";
strscript += "window.close();";
strscript += "</script>";
response.write(strscript);
}
点击open按钮弹出subform.aspx,subform.aspx页面上有textbox1文本框和close按钮
点击close按钮关闭subform.aspx页面,并把子页面subform.aspx文本框的值显示到父页面parentform.aspx 的文本框上。
父窗体前台代码:
复制代码 代码如下:
<script type="text/javascript">
function opensubform(ret) {
var strpath = "subform.aspx"
var nheight = 500
var nwidth = 500
var feature
feature = "height= " + nheight + ",width=" + nwidth + ",top=30,left=30";
feature += ",dependent=yes,location=no,resizable=yes,scrollbars=yes,status=yes,toolbar=no;";
window.open(strpath+"?ret_form=form1&ret_value="+ret,'subform',feature).focus();
return false;
}
</script>
父窗体后台代码:
复制代码 代码如下:
private void page_load(object sender, system.eventargs e)
{
// ページを初期化するユーザー コードをここに挿入します
this.button1.attributes.add("onclick","return opensubform('textbox1');");
}
子窗体后台代码:
复制代码 代码如下:
private void button1_click(object sender, system.eventargs e)
{
string strscript =string.empty;
string strretform = string.empty;
string strretvalue=string.empty;
strretform=request.params["ret_form"];
strretvalue=request.params["ret_value"];
if (strretform == string.empty)
{
strretform= "document.forms[0]";
}
strscript = "<script language=javascript>";
strscript += "window.opener." + strretform;
strscript += "." + strretvalue + ".value='" + this.textbox1.text.trim() + "';";
strscript += "window.close();";
strscript += "</script>";
response.write(strscript);
}
上一篇: Log4j_配置方法(全面讲解)
下一篇: 详细讲解安全升级MySQL的方法