簡體   English   中英

在后面的代碼中生成動態點擊事件

[英]generating dynamic click event in code behind

我在共享點的可視Web部件中生成動態html。

 htmlString = "<a href='#'  onclick='updateAge(" + itemId + ")'>";

我想在click事件的C#后面的代碼中編寫click事件。 click事件應接受參數。

如何實現呢? 我可以通過編寫函數輕松地執行此javascript,但不確定我在后面的代碼中如何做。

假設您已經解決了發送鏈接html的方法,並且只需要發送Javascript,則可以使用Page.ClientScript.RegisterStartupScript

string script = @"function updateAge(itemId) { 
    // here write your logic!
    alert(itemId);
    someOtherFunction();
}

function someOtherFunction() {
    // your logic for this other function
}";
Page.ClientScript.RegisterStartupScript(GetType(), "myscript", script, true);

暫無
暫無

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

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