Server Side Function Calling Client Side Javascript Function For Results
You might have to use AJAX. Have your server code call the popup and have the popup call another method in the server side to process when the user submits. AJAX can do the client call to the server side. so your initial method would just bring up the popup and AJAX would call another method on the server to handle the submit.
Call Code Behind Function from JavaScript (not AJAX!)
Here's how I did it...
<script type="text/javascript">
function AddParticipant(companyid, employeenumber)
{
$("#AddParticipantPanel").dialog("close");
var myargs = {CompanyId: companyid, EmployeeNumber: employeenumber};
var myargs_json = JSON.stringify(myargs);
__doPostBack('<%= SelectParticipantBtn.UniqueID %>', myargs_json);
}
</script>
<asp:Button runat="server" ID="SelectParticipantBtn" ClientIDMode="Static" OnClick="SelectParticipantBtn_Click" style="display:none;" />
And on the server side...
/* this is an inner class */
public class SelectParticipantEventArgs
{
public string CompanyId {get; set;}
public string EmployeeNumber {get; set;}
}
protected void SelectParticipantBtn_Click(object sender, EventArgs e)
{
string args = Request.Form["__EVENTARGUMENT"];
var myargs = JsonConvert.DeserializeObject<SelectParticipantEventArgs>(args);
string emp_no = myargs.EmployeeNumber;
string company_id = myargs.CompanyId;
//do stuff with my arguments
}
Instead of using HiddenFields, I used a hidden button. This model works better because I can go directly to the button's event handler instead of having to add code to the Page_Load function.
How to call a codebehind function from javascript in asp.net?
in JavaScript:
document.getElementById("btnSample").click();
Server side control:
<asp:Button runat="server" ID="btnSample" ClientIDMode="Static" Text="" style="display:none;" OnClick="btnSample_Click" />
C#
protected void btnSample_Click(object sender, EventArgs e)
{
}
It is easy way though...
Calling JavaScript Function From CodeBehind
You may try this :
Page.ClientScript.RegisterStartupScript(this.GetType(),"CallMyFunction","MyFunction()",true);
Related Topics
How to Get My C# Program to Sleep for 50 Msec
How to Extract Data from a Datatable
ASP.NET - Problems with Static Selected Style for a Selected Page on the Menu
How to Pass Constructor Parameters to Unity's Resolve() Method
How to Avoid System.Io.Pathtoolongexception
How to Read User Input from the Console
Remote Validation for List of Models
Swagger UI Web API Documentation Present Enums as Strings
Converting Svg to Png Using C#
Is There a Difference Between I==0 and 0==I
ASP.NET Page Is Not Loading CSS Styles
How to Request Administrator Permissions When the Program Starts
Why Aren't C# Static Class Extension Methods Supported
Linq - Left Join on Multiple (Or) Conditions
When I Post Back to My Controller All Values for My Model Are Null