我想从我的代码隐藏中调用一个 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/