c# - 从页面 *.aspx.cs 调用 javascript 函数

标签 c# javascript asp.net button

我想从我的代码隐藏中调用一个 javascript 函数。 在我的按钮单击事件处理程序中,我有:

protected void load_data_Click(object sender, EventArgs e)
{
    if (dt.Rows.Count == 1)
        {
            BindDl();                       
        }
        else
        {
            //if dt.rows.count! = 1 I want to call a JavaScript function where be one alert! how to do?
        }
}

最佳答案

This page will be helpful for you

// Get a ClientScriptManager reference from the Page class.
ClientScriptManager cs = Page.ClientScript;
Type cstype = this.GetType();
String csName = "MyAlertFunction";

// Check to see if the startup script is already registered.
if (!cs.IsStartupScriptRegistered(cstype, csName))
{
  String jsFunction = "yourFunctionHere()";
  cs.RegisterStartupScript(cstype, csName, jsFunction, true);
}

关于c# - 从页面 *.aspx.cs 调用 javascript 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9433609/

相关文章:

c# - 如何使用自定义数据源从 ListView 中删除项目?

javascript - ASPX 页面上的 C# 值在刷新时合并

c# - 在 ColdFusion 中加密,在 C# 中解密

javascript - svgjs - 加载外部 svg 文件

c# - 将 GridView 导出到 excel 并将 excel 文件保存到文件夹

javascript - 在 js 或 Jquery 中还原 removeAttr

javascript - innerHTML 未在 DOM 中显示,控制台中没有错误

asp.net - WebAPI 中的 DTO 和投影

c# - "mocking"开发中的一个类

c# - 如何在 .net 中有条件地继承类