如何从服务器端按钮单击事件调用javascript函数 [英] How to call javascript function from server side button click event
本文介绍了如何从服务器端按钮单击事件调用javascript函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想从服务器按钮点击事件中调用客户端java脚本函数。
我尝试了但它不起作用。在我的项目中,当我从母版页中删除更新面板时我在主页面中设置了更新面板它工作正常,但是当我设置更新面板然后代码无法正常工作。
这里是代码
Hi,
I want to call client side java script function from server button click event.
I am tried but its not working. In my project I set update panel in master page when I remove update panel from master page it work fine but when I set update panel then code not working.
here is the code
<script type="text/javascript" >
function abc(obj) {
BootstrapDialog.confirm(obj, function (result) {
if (result) {
} else { return false; }
});
}
</script>
protected void Button1_Click(object sender, EventArgs e)
{
this.Page.ClientScript.RegisterStartupScript(this.GetType(), "Warning","abc('test')",true);
}
请告诉我如何使用更新面板实现它。
谢谢
Please sugggest me how to implement it using update panel.
thank you
推荐答案
试试这个..
Try this..
// if you are using Ajax update panel use ScriptManager.RegisterClientScriptBlock
ScriptManager.RegisterClientScriptBlock(this,this.GetType(), "Warning", "abc('test')", true);
// if not Ajax Update panel
this.Page.ClientScript.RegisterStartupScript(this.GetType(), "Warning", "abc('test')", true);
这篇关于如何从服务器端按钮单击事件调用javascript函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文