2015-06-03 32 views
0

我在SharePoint中的視覺web部件中生成動態html。在後面的代碼中生成動態點擊事件

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

我想寫點擊事件在c#中的代碼後面的代碼點擊事件。點擊事件應該接受參數。

如何實現這一目標?我可以通過編寫函數輕鬆完成此JavaScript,但不知道如何在代碼後面執行此操作。

回答

1

假設你已經解決了如何發送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); 
+0

在哪裏寫updateAge方法裏面的代碼?真的很感激,如果有一些例子 – Happy

+0

記住我想寫的所有代碼後面,而不是在javascript – Happy

+0

看到我的答案編輯,看看澄清 –

相關問題