C# 关闭弹出窗口后重新加载dropdownlist

C# 关闭弹出窗口后重新加载dropdownlist,c#,asp.net,C#,Asp.net,我有一个由我的数据库填充的dropdownlist和我的page1上的一个按钮,现在当我单击按钮page2将弹出一个包含1个文本框和2个按钮的窗口,如果我在文本框中输入一个值并单击保存按钮,它将保存在我的数据库上,当我单击关闭按钮时,弹出窗口将关闭,然后我想要的是我在第1页上的下拉列表将重新加载(不重新加载整个页面),以便获得我在弹出窗口中输入的值。到目前为止,我得到的是: 第1页: protected void Page_Load(object sender, EventArgs e) {

我有一个由我的数据库填充的dropdownlist和我的page1上的一个按钮,现在当我单击按钮page2将弹出一个包含1个文本框和2个按钮的窗口,如果我在文本框中输入一个值并单击保存按钮,它将保存在我的数据库上,当我单击关闭按钮时,弹出窗口将关闭,然后我想要的是我在第1页上的下拉列表将重新加载(不重新加载整个页面),以便获得我在弹出窗口中输入的值。到目前为止,我得到的是:

第1页:

protected void Page_Load(object sender, EventArgs e)
{

    Button1.Attributes.Add("onclick", "window.open('Entry.aspx','','height=200,width=650');return false");

}
第2页:

protected void btnSave_Click(object sender, EventArgs e)
{
    try
    {
        if (txtfname.Text == String.Empty)
        {
            lblname.Text = "First Name Required";
            lblname.Visible = true;
        }
        else if (txtlname.Text == String.Empty)
        {
            lbllname.Text = "Last name Required";
            lbllname.Visible = true;
        }
        else
        {
            SqlConnection con = new SqlConnection("Data Source=GATE-PC\\SQLEXPRESS;Initial Catalog=dbProfile;Integrated Security=True");
            SqlCommand cmd = new SqlCommand("insert", con);
            cmd.CommandType = System.Data.CommandType.Text;

            cmd.Parameters.AddWithValue("@Lname", txtlname.Text);
            cmd.Parameters.AddWithValue("@Mname", txtmname.Text);
            cmd.Parameters.AddWithValue("@Fname", txtfname.Text);
            cmd.Parameters.AddWithValue("@checkbox1", CheckBox1.Checked);

            cmd.CommandType = System.Data.CommandType.StoredProcedure;
            con.Open();
            cmd.ExecuteNonQuery();
            MessageBox("successfully saved!");
            clear();
        }
    }
    catch (Exception exe)
    {
        throw exe;
    }
}
protected void btnClose_Click(object sender, EventArgs e) 
{ 
   Response.Write("window.opener.location.reload();self.close();"); 
}

有人帮我做这个。我将asp.net与c#一起使用。谢谢。

在btnClose\u点击

Response.Write("<script type='text/javascript'>;window.close();</script>");
Response.Write(“;window.close();”);
并将以下脚本添加到Entry.aspx

<script type="text/javascript">
    window.onunload = refreshParent;
    function refreshParent() {
        var loc = window.opener.location;
        window.opener.location = loc;

    }

</script>

window.onunload=refreshParent;
函数refreshParent(){
var loc=窗口打开器位置;
window.opener.location=loc;
}

为什么不在
更新面板中添加下拉列表
,当您单击“关闭”按钮时,只需使用
\u doPostBack()
更新更新面板,而不更新整个页面

在javascript中单击关闭按钮时编写以下代码-

onclick="__doPostBack('UpdatePanel1', '');"
ASP.NET AJAX框架将拦截回发,并在此处触发部分回发


虽然直接调用uu doPostBack()是一种不好的做法,但它可以为您的应用服务。您可以在父窗口中创建一个函数,通过ajax加载下拉列表

要从弹出窗口调用该函数,请执行以下操作:

window.onunload = reloadDropDown;
function reloadDropDown() {
    window.opener.reloadDropDown();
}
在父窗口中创建一个名为“reloadDropDown”的函数,并编写代码以使用ajax重新加载值

希望能有帮助


如果您对我的答案有任何疑问,请发表评论。

您好,谢谢您的回复,我已经尝试了您的代码,但整个页面仍在刷新,我正在尝试的只是重新加载下拉列表。再次感谢