简体   繁体   English

ASP.NET / C#-如何弹出带有列表框/多选控件的页面并将选定的ID发送回父页面

[英]ASP.NET / C# - How to pop up a page with a listbox / multi-select control and send the selected IDs back to the parent page

I want to make a pop-up page that contains a listbox-type (multiselect) control which will return the selected IDs to the page that initiated the pop-up. 我想制作一个包含列表框类型(多选)控件的弹出页面,该控件会将选定的ID返回到启动弹出窗口的页面。

This is an ASP.NET web application / C# 3.5 / Latest jQuery. 这是一个ASP.NET Web应用程序/ C#3.5 /最新的jQuery。

I understand how to make the pop-up page with the corresponding controls, but I am unsure about the best way to approach sending an array of item IDs back to the parent page. 我知道如何使用相应的控件制作弹出页面,但是我不确定将项目ID数组发送回父页面的最佳方法。

Is there a way I can leverage JSON, or some other technology to get these item IDs back to the parent page? 有没有一种方法可以利用JSON或其他技术将这些项目ID返回到父页面? At this point in time, I am only familiar with using session variables / querystrings / calls to web services to pass items from page-to-page. 目前,我只熟悉使用会话变量/查询字符串/对Web服务的调用来逐页传递项目。

The one-dimension array will most likely be either ints or strings, but there can possibly be over 40 items selected from the pop-up page. 一维数组很可能是整数或字符串,但是可能会从弹出页面中选择40多个项目。

High-level concepts only needed. 仅需要高级概念。 I can research the exact implementation, once I know what I am looking for. 一旦知道要查找的内容,便可以研究确切的实现。

Thank you so much! 非常感谢!

You can use jQuery UI's dialog and keep the listbox on the page. 您可以使用jQuery UI的对话框,并将列表框保留在页面上。 Then, you would access the selected values in the same way as if they were a control on the page. 然后,您将以与选择值相同的方式访问它们,就像它们是页面上的控件一样。 The only thing to keep in mind is that once you've created the dialog, you'll have to add it back as a child of the form. 唯一要记住的是,一旦创建了对话框,就必须将其重新添加为表单的子级。 ( See this post ) 请参阅这篇文章

This is added overhead if the users will rarely use this popup functionality, but it's a lot cleaner from a development and maintenance point of view. 如果用户很少使用此弹出功能,则会增加开销,但是从开发和维护的角度来看,它要干净得多。 Also, it's only one or two extra controls and 10-20 lines of javascript. 此外,它只是一两个额外的控件和10到20行的javascript。

I've spent hours tracing a web of popups passing javascript around between controls, pages, and parent pages (iframes, ugh), and it's a lot easier when you're just hiding/showing a div on the same page. 我已经花费了数小时来追踪弹出窗口的网络,以在控件,页面和父页面(iframe,ugh)之间传递javascript,而当您在同一页面上隐藏/显示div时,这要容易得多。

I did something that you wrote about 1 month ago. 我做了大约1个月前您写的内容。 The way that I choose based on using javascript without json, but you can do it. 我基于不使用json的javascript选择的方式,但是您可以做到。 Here is some code, that will help you Popup.ascx 这是一些代码,可以帮助您Popup.ascx

` `

function SubmitChangnes(id) {
if (window.opener && !window.opener.closed)
        {
            var value = document.getElementById("hiddenid").value;
            window.close();
            window.opener.addPerson(document.getElementById("hiddenid").value, document.getElementById("TextBox2").value);
        }
    }

` `

When you press submit button on Popup page, it call SubmitChanges, that close popup window and call function in parent window. 当您在“弹出”页面上按“提交”按钮时,它将调用SubmitChanges,它关闭弹出窗口并在父窗口中调用函数。 In your case you can send json object to parent window function 您可以将json对象发送到父窗口函数

Variation on DanTheMan's answer: DanTheMan答案的变化:

function returnSelected(form) {
    if (window.opener && !window.opener.closed) {
        $('#selectList :selected').each(function(i, selected) {
            window.opener.$("#list")
                .append('<li>' + $(selected).text() + '</li>');
        });
    }
}
private void Get_Terms_And_Delivery()
{

    if (txtHidden_Terms_And_delivery1.Value != "")
    {
        string strHidden_Terms_And_Delivery_Id = "";
        if (ViewState["intTerms_Of_Delivery_Id"] != null)
        {
            strHidden_Terms_And_Delivery_Id = ViewState["intTerms_Of_Delivery_Id"].ToString();
        }
        if (strHidden_Terms_And_Delivery_Id != txtHidden_Terms_And_delivery1.Value)
        {
            ViewState["intTerms_Of_Delivery_Id"] = Convert.ToInt32(txtHidden_Terms_And_delivery1.Value);


            Parameterised_SQL_Dentry pm = new Parameterised_SQL_Dentry(1, CommonStrings.ConnectionString);
            string str_Select = "select  vcrTerm_1,vcrTerm_2,vcrTerm_3,vcrTerm_4,vcrTerm_5,vcrTerm_6 from exp_mst_Terms_Of_Delivery where intTerms_Of_Delivery_Id=@intTerms_Of_Delivery_Id";
            pm.Parameters.Add("@intTerms_Of_Delivery_Id", SqlDbType.Int, txtHidden_Terms_And_delivery1.Value);

            DataTable dt = new DataTable();
            dt = pm.GetDataTable(str_Select);
            if (dt.Rows.Count > 0)
            {
                txtPacking_List_Notify_Terms1.Text = dt.Rows[0]["vcrTerm_1"].ToString();
                txtPacking_List_Notify_Terms2.Text = dt.Rows[0]["vcrTerm_2"].ToString();
                txtPacking_List_Notify_Terms3.Text = dt.Rows[0]["vcrTerm_3"].ToString();
                txtPacking_List_Notify_Terms4.Text = dt.Rows[0]["vcrTerm_4"].ToString();
                txtPacking_List_Notify_Terms5.Text = dt.Rows[0]["vcrTerm_5"].ToString();
                txtPacking_List_Notify_Terms6.Text = dt.Rows[0]["vcrTerm_6"].ToString();

            }
        }
    }
    txtHidden_Terms_And_delivery1.Value = "";
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM