首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

如何在后台调用button控件的onclick事件

2012-03-27 
怎么在后台调用button控件的onclick事件页面中有个按钮名称为btnclose,属性为隐藏,我希望在别的地方调用他

怎么在后台调用button控件的onclick事件
页面中有个按钮名称为btnclose,属性为隐藏,我希望在别的地方调用他的onclick事件来关闭当前页面
在cs文件里加上这一句
btnclose.Attributes.Add("onClick", "win.removewin(win.currentwin)");
这表示给btnclose加个onclick事件,还需要手工去调用这个事件才能执行吗?请问要怎么让他执行btnclose的onclick事件呢?

[解决办法]
在后台调用
比如你的后台代码为:
 protected void BtnSubmit_Click(object sender, EventArgs e)
 {
//your code
}

在其他方法调用时
BtnSubmit_Click(null,null);
[解决办法]
ClientScript.RegisterStartupScript(this.GetType(), "a", "<script>win.removewin(win.currentwin)</script>");

 
 
 
 
----------------------------------签----------名----------栏----------------------------------
[解决办法]
其实你可以把btnclose事件写在js里,在后台调用
Page.RegisterClientScriptBlock("btnclose", "<script>btnclose()</script>");
[解决办法]
看标题,是调用onclick事件,不是调函数,所以:
ClientScript.RegisterStartupScript(this.GetType(), "", "<script>btnclose.onclick();</script>");


[解决办法]
btnclose.click(); //并且不是所有浏览器都支持。
[解决办法]
参考

热点排行