客户端模板按钮事件未触发
client template button event not firing
当用户单击按钮时,我正在尝试显示一个弹出窗口,但我似乎无法让它工作。我可以在使用自定义命令时触发事件,但我需要在同一列中彼此相邻的文本框和按钮。
任何想法为什么这不起作用?
@(Html.Kendo().Grid(Model)
.Name("gridPopup")
.Columns(columns =>
{
columns.Bound(p => p.ProductName).Width(120);
columns.Template(@<text></text>).Title("").Width(110).ClientTemplate(
Html.Kendo().TextBox()
.Name("search_textfield")
.Value("").ToClientTemplate().ToString()
+ " " +
Html.Kendo().Button()
.Name("search_button")
.HtmlAttributes(new { type = "button", @class = "k-primary" })
.Events(e =>
e.Click("SearchButton")
)
.Content("...").ToClientTemplate().ToString()
);
})
.Editable(editable => editable.Mode(GridEditMode.InCell))
.Pageable()
.Scrollable()
.HtmlAttributes(new { style = "height:320px;" })
.DataSource(dataSource => dataSource
.Ajax()
.Batch(true)
.PageSize(20)
.ServerOperation(false)
.Events(events => events.Error("errorHandler"))
.Model(model =>
{
model.Id(p => p.ProductID);
model.Field(p => p.ProductID).Editable(true);
model.Field(p => p.CategoryID).DefaultValue(1);
})
.Read(read => read.Action("ForeignKeyColumn_Read", "Home"))
.Update(update => update.Action("ForeignKeyColumn_Update", "Home"))
.Create(create => create.Action("ForeignKeyColumn_Create", "Home"))
.Destroy(destroy => destroy.Action("ForeignKeyColumn_Destroy", "Home"))
)
)
<script type="text/javascript">
function errorHandler(e) {
if (e.errors) {
var message = "Errors:'n";
$.each(e.errors, function (key, value) {
if ('errors' in value) {
$.each(value.errors, function () {
message += this + "'n";
});
}
});
alert(message);
}
}
function SearchButton(e)
{
alert("Search Button Clicked");
}
</script>
奇怪! 如果在 ClientTemplate() 中使用,.Events(e => e.Click("SearchButton"))
不会生成 onclick 属性
试试这个,它会为你工作,但我会等待有人解释它:)
.HtmlAttributes(new { type = "button", @class = "k-primary", onclick = "SearchButton()" })
编辑:我找到的解释在这里:如何在网格客户端列模板中使用剑道 UI 小部件?它说script tags are not automatically evaluated inside a Grid client column template, so any included widgets will not be initialized.
因此,初始化 .Events(e => e.DataBound("onDatabound"))
中的嵌套控件
function onDatabound()
{
jQuery("#gridPopup tbody [class='k-primary']").each(function () {
$(this).kendoButton({ "click": SearchButton });
})
}
相关文章:
- ASP.NET通过单击JavaScript按钮触发c#事件
- 当我点击jsf中的primefaces命令按钮时,如何获得点击事件
- 鼠标悬停事件影响列表中所有行中的按钮,而不仅仅是特定按钮
- 如何在不单击javascript中的按钮的情况下触发事件
- 如何隐藏按钮单击事件上的占位符
- 如何使用for循环添加所有按钮'单击事件
- 单击按钮前运行事件
- 主干点击事件按钮不工作
- 切换事件按钮
- 从javascript onclick事件按钮调用c函数
- 点击加载事件按钮
- 在.remove()和.append()之后返回我的事件按钮
- 如何在javascript中启用或禁用文本框的按键事件按钮
- 如何添加onclick事件按钮在yii引导(http://www.cniska.net/yii-bootstrap/#t
- 如何打开弹出窗口旁边的事件按钮-如何获得鼠标光标位置onclick
- 单击事件按钮正在发送图标作为目标
- 添加要提交的事件按钮
- Jquery移动处理器事件按钮
- Js移动网络事件按钮
- 为什么在HTML按钮的属性窗口中没有事件按钮