I tried to call a c# function from JavaScript – I want to pass the parameter along with that method, but how do I pass the parameter?
Below is the javascript in the aspx page:
function CallCodeBehind(id) {
var a = '<%=CallFromJS(--parameter need pass here --)%>';
}
The below method is in the code-behind
public string CallFromJS(id) {
int id=id;
getNames(id);
return null;
}
And the Button code is:
<Button ID="Button1" runat="server" OnClientClick="CallCodeBehind(<%=(id)%>)" Text="Upload" />
WebMethods can have parameters, but method has to be static.
Server side (*.cs code behind) :
And then call it from javascript like this :
and button :
Of course id has to be public, and on that form you have to have ScriptManager with PageMethods enabled, like this :