簡體   English   中英

在 JavaScript 中調用 Function 后面的代碼

[英]Calling Code behind Function in JavaScript

我想通過 javascript 調用 function,但我收到一條錯誤消息“CS0103:當前上下文中不存在名稱‘bidindex’”你能幫幫我嗎? 謝謝

JS代碼

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

.cs 代碼

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

就像homungus所說,您的代碼隱藏中的方法必須是 static WebMethod。

它可能是這樣的:

JS代碼

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

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

.CS 代碼

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

還有一個有用信息的有用鏈接: asp.net 中的頁面方法

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM