0
votes

I have a dropdownlist populated by my database and a button on my page1, now when I click the button page2 will popup which contains of 1 textbox and 2 buttons, if I enter a value in my textbox and click the save button, it'll save on my database and when i click the close button, popup will close then what I want is my dropdown on page1 will reload (without reloading the entire page) in order to get the value that I entered in popup window. This is what I have got so far:

Page1:

protected void Page_Load(object sender, EventArgs e)
{

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

}

Page2:

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();"); 
}

Someone kindly help me with this. i am using asp.net with c#. Thanks.

3

3 Answers

1
votes

you can create a function in the parent window that loads the Dropdown by ajax.

to call that function from the popup:

window.onunload = reloadDropDown;
function reloadDropDown() {
    window.opener.reloadDropDown();
}

create a function named 'reloadDropDown' in the parent window and write code to reload the values using ajax...

Hope it helps.

Plz do comment if you have any issues regarding my answer.

0
votes

Write inside btnClose_Click

Response.Write("<script type='text/javascript'>;window.close();</script>");

and add following script to Entry.aspx

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

    }

</script>
0
votes

Why don't you add your dropdownlist in an UpdatePanel and when you click on 'Close' button just use __doPostBack() to update UpdatePanel only and not the entire page.

Write following code onclick of close button in javascript-

onclick="__doPostBack('UpdatePanel1', '');"

ASP.NET AJAX framework will intercept the postback and will fire a partial postback here.

Although it's a bad practice to call __doPostBack() directly but it can serve your pourpose.