JS使用showModalDialog返回值

1、//跳转的超链接

<a href="javascript:void(0);" onclick="openSub();return false;" class="acss" runat="server"
            id="lnkAddDetail">選擇</a>

//子页面的返回值带回到父页面的DropDownList_F27中

<asp:DropDownList runat="server" ID="DropDownList_F27" CssClass="pub_clsInputSelect DropDownListElement FORM6_ID"
            Enabled="true" AutoPostBack="True" Width="155px" OnSelectedIndexChanged="DropDownList_F27_SelectedIndexChanged">
        </asp:DropDownList>

2、

<script language="javascript" type="text/javascript">
        //选择人力需求单
        function openSub() {
            var totalRows = $("#<%=GridView_SUB1.ClientID %> tr").length - 1;
            var returnValue = window.showModalDialog('SelectHrForm.aspx?TOTALCOUNT=' + totalRows, '', 'dialogWidth=1000px;dialogHeight=600px');
            var objList = document.getElementById("<%=DropDownList_F27.ClientID%>");
            for (var i = 0; i < objList.options.length; i++) {
                if (objList.options[i].text == returnValue) {
                    objList.options[i].selected = true;
                }
            }
            document.getElementById("<%=hdnChange.ClientID%>").click();

        }
    </script>

3、子页面代码

RegisterScript(string.Format("window.returnValue = '{0}';window.close()", strHrNeedFormId), true);//保存返回的值,并关闭子页面

//注册脚本

        public void RegisterScript(string script, bool isAfter)
        {
            if (isAfter)
                ClientScript.RegisterStartupScript(typeof(System.Web.UI.Page), Guid.NewGuid().ToString(), script, true);
            else
                ClientScript.RegisterClientScriptBlock(typeof(System.Web.UI.Page), Guid.NewGuid().ToString(), script, true);
        }

下面讲使用showModalDialog普通跳转,不带返回值

<asp:GridView ID="grdProcessing_Status"  OnRowCommand="grdProcessing_Status_RowCommand">

       <ItemTemplate>
                           <asp:LinkButton ID="Label2" runat="server" CommandName="Details" CommandArgument='<%# DataBinder.Eval(Container,"DataItem.FORM_NO") %>' Text='<%# DataBinder.Eval(Container, "DataItem.SerialNO")%>'>         
                             </asp:LinkButton>
         </ItemTemplate>

protected void grdProcessing_Status_RowCommand(object sender, GridViewCommandEventArgs e)
        {

                //詳細
                if (e.CommandName == "Details")
                {
                    GridViewRow row = ((LinkButton)e.CommandSource).Parent.Parent as GridViewRow;
                    string formNO = e.CommandArgument.ToString();
                    ScriptStartup("window.showModalDialog('../CARRFORM1_View/Main.aspx?FORM_NO=" + formNO + "','','dialogWidth:800px;dialogHeight:700px;center:yes;help:no;status:no;resizable:yes');");
                }

}

原文地址:https://www.cnblogs.com/Chinarain/p/3821965.html