Skip to main content
 首页 » 编程设计

javascript之如何从 aspx.cs 调用 javascript 方法

2024年05月10日33zhwl

我想在选择 listbox1 项时从 aspx.cs ( c# ) 在 javascript 中调用方法 hello()。使用此代码来执行此操作但无法正常工作

protected void ListBox1_TextChanged(object sender, EventArgs e) 
    { 
        ClientManager.RegisterStartupScript(this, GetType(), "whatiskey","hello();", true);  
    } 

    function hello() { 
alert("hiiiii"); 
 var arr = ["<%=myvalue %>"]; 
 
 
            } 

请您参考如下方法:

将 ListBox 的“AutoPostBack”属性设置为“true”并使用 Page.ClientScript.RegisterStartupScript(GetType(), "whatiskey", "hello();", true); 对我有用