Click here to Skip to main content
15,920,053 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hello friends

I have javascript function
function fillVC(e)
{
    .....
} 


I call this function in two control events
1.  <asp:DropDownList ID="ddlGeo" runat="server" Width="100px" 
                     onChange="fillVC(this);">
                </asp:DropDownList>   (in .aspx file)

2.  <asp:Button runat="server" id="btnSearch" Text="Search" 
                        onclick="btnSearch_Click"/>

protected void btnSearch_Click(object sender, EventArgs e)
    {
        this.GVDatabind();
        ClientScript.RegisterStartupScript(typeof(Page), "Open", "fillVC(this);", true);
    }        (in code behind file) 


Can anyone tell me how I can determine which control has called the javascript, based on that I can take different action in same function

Any idea how to do this??

Thanks in advance
Posted

1 solution

Based on the ID of the control we could use the control.type to check the type of the control.


JavaScript
function fillVC(controlClientId)
        {

            
            var control = document.getElementById(controlClientId);

            alert(control.type);

            if (control != null && control.type == "submit") {
                //control is a button
                alert('button')

            }

            else if (control != null && control.type == "select-one") {

                //control is dropdownlist 
                alert('dropdown')

 	}



You need to call the function like this...

ASP.NET
<asp:dropdownlist id="ddlGeo" runat="server" width="100px" onchange="fillVC(this.id);" xmlns:asp="#unknown">
</asp:dropdownlist>
 
Share this answer
 
Comments
Vani Kulkarni 21-Jun-12 5:33am    
Good Answer 5!

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