asp.net调用JS方法的问题

whblxl whblxl 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区

我在asp.net多次调用js方法(不用button click方式),场景是后台数据更新后激活前台刷新页面

ClientScript.RegisterStartupScript只执行一次(key是变量)

js方法:

function test(tt)
{
    alert('test'+tt);
}

cs

        private static void Data_Monitor()
        {            
            using (SqlConnection connection = new SqlConnection(_connStr))
            {
                string mntSql = "select ID,BH,MONITOR_DT,MONITOR_VALUE From [dbo].[MONITOR_REALTIME]";
                using (SqlCommand command = new SqlCommand(mntSql, connection))
                {
                    command.CommandType = CommandType.Text;
                    connection.Open();
                    SqlDependency dependency = new SqlDependency(command);
                    dependency.OnChange += new OnChangeEventHandler(dependency_OnChange);
                    command.ExecuteNonQuery();
                    
                    currentPage.ClientScript.RegisterStartupScript( currentPage.GetType(),"js"+jsCount.ToString(), "<script>test(111);</script>");
                    jsCount++;
                }
            }
        }

   currentPage.ClientScript.RegisterStartupScript( currentPage.GetType(),"js"+jsCount.ToString(), "<script>test(111);</script>"); 只执行一次

 

如果在button_click中就点一次按钮执行一次

请问谁遇到过类似问题?谢谢

...全文
评论 1
收藏 已收藏
分享
返回顶部
whblxl
.NET社区 62,272 成员 668,968 内容