ShowModalDialog的解决办法


我们要实现如下功能。页面上有一个TextBox(id=tbCustCode)和一个ImageButton(id=IBS
elCustCode),我们点击这个ImageButton然后弹出一个模态的选择窗口,选中后把选中的东
西写入TextBox中。

代码如下:

首先在你的.aspx文件中写入这个函数。
function openDialog(url, height, width)
{
var returnString;
var obj = Form1;
returnString = window.showModalDialog(url, obj,'dialogHeight:'+height+'px;di
alogWidth:'+width+'px;edge:Raised;center:Yes;help:Yes;resizable:No;status:No;s
croll:No');
return returnString;
}

在你的主页面的.vb文件中
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventAr
gs) Handles MyBase.Load
   IBSelCustCode.Attributes.Add("onclick", "javascript:return openDialog(Popu
p/SelCustomerPopup.aspx','400','550')")
End Sub

在你的SelCustomerPopup.aspx文件的<HEAD></HEAD>中加入
<BASE target="_self">
<script language="javascript">
window.returnValue=false;
</script>

在你的SelCustomerPopup.aspx的vb文件中

在你选中数据的事件中(比如我们用一个DataGrid来显示数据,选中某行,
那么就在ItemCommand事件中)写入
 
                   Dim Script As String
                   Script = "<script language=JavaScript>" & _
                            "window.returnValue=true;" & _
                            "dialogArguments.tbCustCode.value='" & e.Item.Cel
ls(2).Text.Replace("&nbsp;", "") & "';" & _
                            "window.close();" & _
                            "</script>"

           RegisterClientScriptBlock("clientScript", Script)

就可以实现以上功能了。


如果我们需要选中数据后要然主页面执行某些代码,那么你就写在ImageButton的Click事件中。

实现的机理其实是把主窗体的Form当作参数传给模态窗口.
posted @ 2005-07-19 11:15  Martin XJ  阅读(433)  评论(0)    收藏  举报