0

I want to call function through javascript, but I get an error message "CS0103: The name 'bidindex' does not exist in the current context" Can you help me? Thanks

JS code

<script>
    function senddata(whatdate, bidindex) {          
        var a = "<%=DatabidGridView1(bidindex,whatdate%>";
    }
</script>

.cs code

public string DatabidGridView1(string sindex, string sdate)
        {
   return "good";
        }
Michael Wu
  • 13
  • 4
  • needs to be a static WebMethod, see here: https://stackoverflow.com/questions/18510749/how-to-call-code-behind-method-from-a-javascript-function – Homungus May 19 '20 at 07:54

1 Answers1

1

Like homungus said the Method in your codebehind has to be a static WebMethod.

It could be something like:

JS Code

$(".clickMe").click(function(){ senddata(data, index) });

function senddata(whatdate, bidindex) {          
   PageMethods.DatabidGridView1(bidindex, whatdate);
}

.CS Code

[WebMethod]
public string DatabidGridView1(string sindex, string sdate)
{return "good";}

Also meby a useful link with useful information: Pagemethods in asp.net