父窗口的label服务器控件从Model Dialog窗口用dialogArguments赋值为何不能保存状态?(思考)
2006-08-18 10:56 BAsil 阅读(1058) 评论(1) 编辑 收藏 举报项目中需要把父窗口的<asp:label>从Model Dialog中赋值,但发现在赋值后,如果父窗口刷新,则无法保存状态。经过一番思考,明白了其中的道理。现在把代码贴出,欢迎大家讨论。
LabelInnerHTMLTest.aspx
<HTML>
<HEAD>
<title>LabelInnerHTMLTest</title>
<script language="C#" runat="server">
public void btn_Click(object sender, EventArgs e)
{
}
</script>
<script>
function addRelation()
{
window.showModalDialog("LabelModel.aspx",window,"center=yes;status=0;dialogHeight=350px;dialogWidth=600px;scroll=no;");
}
</script>
</HEAD>
<body MS_POSITIONING="FlowLayout">
<form id="Form1" method="post" runat="server">
<asp:label id="Label1" runat="server">Label</asp:label><asp:textbox id="TextBox1" runat="server"></asp:textbox><INPUT onclick="addRelation();" type="button" value="模式窗口">
<asp:button id="Button1" runat="server" OnClick="btn_Click" Text="PostBack"></asp:button>
</form>
</body>
</HTML>
LabelModel.aspx<HEAD>
<title>LabelInnerHTMLTest</title>
<script language="C#" runat="server">
public void btn_Click(object sender, EventArgs e)
{
}
</script>
<script>
function addRelation()
{
window.showModalDialog("LabelModel.aspx",window,"center=yes;status=0;dialogHeight=350px;dialogWidth=600px;scroll=no;");
}
</script>
</HEAD>
<body MS_POSITIONING="FlowLayout">
<form id="Form1" method="post" runat="server">
<asp:label id="Label1" runat="server">Label</asp:label><asp:textbox id="TextBox1" runat="server"></asp:textbox><INPUT onclick="addRelation();" type="button" value="模式窗口">
<asp:button id="Button1" runat="server" OnClick="btn_Click" Text="PostBack"></asp:button>
</form>
</body>
</HTML>
<HTML>
<HEAD>
<title>LabelModel</title>
<script>
function chooseYSCred()
{
var targetSummary="test from model";
window.dialogArguments.document.getElementById("Label1").innerHTML=targetSummary;
window.dialogArguments.document.getElementById("TextBox1").value=targetSummary;
window.close();
}
</script>
</HEAD>
<body MS_POSITIONING="FlowLayout">
<form id="Form1" method="post" runat="server">
<INPUT onclick="chooseYSCred();" type="button" value="Button">
</form>
</body>
</HTML>
<HEAD>
<title>LabelModel</title>
<script>
function chooseYSCred()
{
var targetSummary="test from model";
window.dialogArguments.document.getElementById("Label1").innerHTML=targetSummary;
window.dialogArguments.document.getElementById("TextBox1").value=targetSummary;
window.close();
}
</script>
</HEAD>
<body MS_POSITIONING="FlowLayout">
<form id="Form1" method="post" runat="server">
<INPUT onclick="chooseYSCred();" type="button" value="Button">
</form>
</body>
</HTML>
从Model Dialog窗口赋值后,点击PostBack按钮,发现TextBox可以保存状态,但是Label的状态丢失。
答案随后给出。