把LinkButton放在GridView's单元格上,当用户点击它时运行javascript函数
Put LinkButton on GridView's cell and run javascript function when user click on it
我在UpdatePanel的页面上添加了一个GridView,并在其中一个单元格中添加了一个面板,并从后面的代码中添加LinkButton到这个面板,如下图
Panel pnl = (Panel)GridView1.Rows[i].Cells[4].FindControl("pnlSteps");//pnlSteps is Panel's Id
LinkButton lnk = new LinkButton();
//...
pnl.Controls.Add(lnk);
当用户点击每个LinkButton时,我想运行一个javascript的函数,我该怎么做?
可以这样使用
Panel pnl = (Panel)GridView1.Rows[i].Cells[4].FindControl("pnlSteps");
LinkButton lnk = new LinkButton();
lnk.attributes.Add("onclick", "YourFunction();");
pnl.Controls.Add(lnk);
在java-script中创建如下函数
<script type="text/javascript">
function YourFunction()
{
alert("function called");
return false;//don't forgot this
}
</script>
像这样在函数上引发OnClick事件
lnk.attributes.Add("onclick", "function()");
相关文章:
- poster typeerror用户不是函数
- 如何通过获取用户输入和使用按钮来运行JavaScript函数
- 如何在 Mozilla 插件中调用用户函数
- 每次用户键入时调用函数
- jquery返回ajax响应和用户定义的变量到函数
- 用户定义的函数在 Angular Cordova 中不起作用
- 为什么不'当用户输入空格或字符太多/不够时,此函数会发出window.alert
- 用户在noConflict mod中使用jQuery定义函数
- 当用户滚动到底部时,Ajax函数会多次触发
- html将输入传递给具有用户输入的函数
- 最佳实践:在网页对用户可见后调用.Net函数
- 如何使用用户定义的相等函数在Javascript中创建一组用户定义的对象
- 在jQuery中:如何在用户展开窗口时更新函数
- 当用户在输入上按下回车键时,我该如何调用函数
- 如何设置用户当前位置以初始化离子框架中的函数
- 如何在javascript中对用户函数进行自定义回调
- 在less.css中创建和使用用户函数
- 为什么人们要在jQuery对象中添加自己的自定义/用户函数
- 外部JS函数onload与用户函数onload冲突
- 是否可以传递'$(this)'到jQuery中的委托用户函数