问题描述
哪位高手帮帮我啊,在线等!在.net中用模态对话框传值出错啊。1.在父窗口中js代码:<scriptlanguage="JavaScript">functionopenMessageWindow(){window.showModelessDialog("ShowMessage.aspx",document.getElementById('txtMessage'),"dialogWidth='500px';dialogHeight='347px';dialogLeft=410;dialogTop=246;resizable='no';status='no';scroll='no'");}</script>2.在弹出窗口中js代码<scriptlanguage="JavaScript">functiongetValue(){varmessage="<%=message%>";window.dialogArguments.value=message;window.close();}</script>后台代码publicpartialclassMessageSend_ShowMessage:System.Web.UI.Page{publicstringmessage="llll";protectedvoidPage_Load(objectsender,EventArgse){}protectedvoidImageButton1_Click(objectsender,ImageClickEventArgse){message=Request.Form.Get("MyRadioButton");}}虽然变量message的值可以传回父窗口txtMessage中,但是每次刷新窗口,或者提交服务器控件时,txtMessage中的值又消失了。这个到底是什么原因呢??
解决方案
解决方案二:
Web的无状态性,每次postback的时候,message值都会被重新初始化,使用以下方法:publicpartialclassMessageSend_ShowMessage:System.Web.UI.Page{protectedvoidPage_Load(objectsender,EventArgse){}protectedvoidImageButton1_Click(objectsender,ImageClickEventArgse){this.message=Request.Form.Get("MyRadioButton");}publicstringmessage{set{ViewState["message"]=value;}get{returnViewState["message"]==null?"llll":ViewState["message"].ToString();}}}
解决方案三:
该回复于2007-12-04 11:17:08被版主删除
解决方案四:
建议:最好就不要用那个