Click here to Skip to main content
15,893,622 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a form with a GridView on it. In the GridView's RowDataBound event I add the onClick event as follow:

C#
e.Row.Attributes.Add("onclick", "divexpandcollapse('" + WorkItemID.Value + "','" + txnID.Value + "')");


I call the the Javascript method "divexpandcollapse" which takes some parameters.

How can I access the onClick event in my code behind file, for example, if the row click happens for a certain row, I need the javascript function to be executed and some method in my code behind file.

Any help would be greatly appreciated.
Posted

javascript :
C#
function divexpandcollapse()
    {
        var bntEvent = document.getElementById("<%= Button2.ClientID %>");
        bntEvent.click();
    }
 
Share this answer
 
Comments
Andrew797 7-Nov-12 2:12am    
I tried this, but it does not seem to reach the click event of the button
 
Share this answer
 
v2
Comments
SoumenBanerjee 7-Nov-12 1:29am    
To execute some method from code behind with javascript method

http://www.codeproject.com/Articles/238866/Invoke-Server-Methods-From-Client-Side-Using-JQuer
http://www.c-sharpcorner.com/UploadFile/abhikumarvatsa/calling-an-Asp-Net-C-Sharp-method-web-method-using-javascript/

http://www.dotnetcurry.com/ShowArticle.aspx?ID=109
Hope these can help...
Andrew797 7-Nov-12 2:52am    
Thanks, the 3rd article seems to have done the trick.

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