Click here to Skip to main content
15,886,860 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a button ImageButton10 in a parent page. In the popup window a button OK is present. I want fire ImageButton10_click event when the OK button of child page or popup window will fire. how to do this. Please help.

My code is as follows
In child page
JavaScript
<script type="text/javascript" language="javascript">
    function RefreshParent() {
        document.getElementById('ImageButton10').Click();
        window.close();
    } 
</script>

ASP.NET
<asp:Button ID="Button2" runat="server"  Text="Ok" 
            Width="123px" onclientClick="RefreshParent();" />


Parent
C#
protected void ImageButton10_Click(object sender, ImageClickEventArgs e)
    {
        con.Open();
        string query = "select distinct Contact_Name from Contact where Account='" + TextBox2.Text + "'";
        DataTable dt = new DataTable();
        SqlDataAdapter adpt = new SqlDataAdapter(query, con);
        adpt.Fill(dt);
        DropDownList6.DataSource = dt;
        DropDownList6.DataTextField = "Contact_Name";
        DropDownList6.DataValueField = "Contact_Name";
        DropDownList6.DataBind();
        con.Close();
        DropDownList6.Items.Insert(0, "<--Select-->");
    }
Posted
Comments
Sinisa Hajnal 2-Apr-15 6:15am    
First of all, getElementById('ImageButton10') will never find your runat server button because asp.net mangles the names of the control. Check page source and you'll see something like ctl00_pnlGrid_ImageButton10 in the control ID.

You have to do something like: document.getElementById('<%=ImageButton10.ClientID%>').Click();

Second, what kind of name is ImageButton10!? Give it some sensible name...and the rest of the controls too (DropDownList6? will you know what is in DDL5 in 6 months?) ! :)
Member 10578683 2-Apr-15 6:36am    
document.getElementById('<%=ImageButton10.ClientID%>').Click();
On writing this an error ImageButton10 does not exit in current context is showing

1 solution

remove your javascript code and add the onclick attribute to your button as below

ASP.NET
<asp:button id="Button2" runat="server" text="Ok"
            Width="123px" OnClick="ImageButton10_Click"  ></asp:button>


you dont want to call script to calling the Server side code.
 
Share this answer
 
v2
Comments
Member 10578683 2-Apr-15 7:16am    
my Button2 is present in popup window and ImageButton10 present in parent page
Solai Raja 3-Apr-15 0:17am    
can you share your full code?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900