admin管理员组文章数量:1426086
I want to call a javascript function from my codebehind. In my button click event handler I have:
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?
}
}
I want to call a javascript function from my codebehind. In my button click event handler I have:
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?
}
}
Share
Improve this question
edited Feb 24, 2012 at 17:23
Ben
7644 silver badges19 bronze badges
asked Feb 24, 2012 at 15:45
AlexAlex
9,74030 gold badges107 silver badges166 bronze badges
2 Answers
Reset to default 2This 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);
}
user scrip manager
ScriptManager.RegisterStartupScript(this, typeof(string), "SHOW_ALERT", "alert('')", true);
where in place of alert you can put your javascript code, next argument true puts in script tags automatically so you dont have to write them.
本文标签: cfrom page *aspxcs call javascript functionStack Overflow
版权声明:本文标题:c# - from page *.aspx.cs call javascript function - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745392957a2656683.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论