如何将onclick属性添加到动态按钮 [英] how to add onclick attribute to dynamic button
本文介绍了如何将onclick属性添加到动态按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您好如何在动态按钮上添加onclick功能..
我这样写
Hi how to add onclick function to the dynamic button..
i wrote like this
for loop
{
ImageButton btn = new ImageButton();
btn.ID = "btn" + i;
btn.ImageUrl = "images/edit.jpg";
//btn.OnClientClick += new EventHandler(get);
btn.Attributes.Add("onclick", "get()");
}
public void get(object sender, EventArgs e)
{
this.mopopupeditrule.Show();
}
在此onclick函数中不起作用..我该如何给出...如果我单击按钮想要显示一个模式弹出窗口..有什么想法吗?
in this onclick function not works..how can i give...if i click button one modalpopup want to show..any idea?
推荐答案
onclick
事件中的服务器端功能.您只能调用Javascript function
.
You can not call a server side function from theonclick
event. You can call only theJavascript function
.
错误:"btn.OnClientClick + = new EventHandler(get);"
尝试:"btn.OnClick + = new EventHandler(get);"
OnClientClick用于客户端事件(Javascript).
如果需要客户端启动客户端事件,请使用"btn.Attributes.Add("onclick","JsFunction()");
Error: "btn.OnClientClick += new EventHandler(get);"
Try: "btn.OnClick += new EventHandler(get);"
OnClientClick is for Client Side events(Javascript).
If you need client fire client side event, Use "btn.Attributes.Add("onclick","JsFunction()");
如果要添加服务器端函数,则
if you wants to add a server side function then
btn.OnClick += new EventHandler(btn_Click);
在这里使用委托附加函数.
如果要添加Javascript函数,请尝试
here Attaching a function using delegate.
If you wants to add a Javascript function then try
btn.Attributes.Add("onclick", "javascript function name");
这篇关于如何将onclick属性添加到动态按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文