Monday, 29 December 2014

Calling Server Side event using Javascript

Scenario : In my case, I want to call/Fire button click event which is in invisible in page using javascript then i googled many sites but none of the solutions are not suite for my requirement. So at last i found the solution. The below method i solved my problem. I hope this will help you to fix the problem.

Pre-requisites : We include ScriptManger into your page.

   <asp:ScriptManager ID="ScriptManager1" runat="server">
    </asp:ScriptManager>

And then we used the below one in any where as per your requirement,

WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions('btnUploadFile', '', true, '', '', false, true));

Example :

Added the WebForm_DoPostBackWithOptions, inside the function,

function Firebutton()
{
       WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions('btnUploadFile', '', true, '', '', false, true));
}

then this fires btnUploadFile_click event.

Now we are knowing about the parameters of  WebForm_DoPostBackWithOptions are below and i mapped the value with above one,

1. eventTarget  - btnUploadFile
2. eventArgument - ''
3. validation - true
4. validationGroup - ''
5. actionUrl - ''
6. trackFocus - false
7. clientSubmit - true

That's It,
Happy Coding :)