获取RadGrid编辑表单中控件的ClientID
我有带有自定义编辑表单的 Telerik RadGrid。在我的编辑表单中,有一个 RadDatePicker,我向其中添加了一个包含“今天”按钮的自定义页脚模板。
在按钮的 OnClick 事件中,我调用一个 Javascript 函数,该函数采用控件 ID 来设置所选日期。
但是,由于该控件位于编辑表单内,因此没有为其创建变量,并且当我尝试获取客户端 ID 时,编译器会抛出错误。
RadDatePicker 声明为:
<telerik:RadDatePicker ID="ControlName" runat="server" SelectedDate='<%# Bind("Field") %>'>
<Calendar ID="Calendar1" runat="server">
<FooterTemplate>
<div style="width: 100%; text-align: center; background-color: Gray;">
<input id="Button1" type="button" value="Today" class="button"
onclick="GoToToday('<%= ControlName.ClientID %>')" />
</div>
</FooterTemplate>
</Calendar>
</telerik:RadDatePicker>
我得到的错误是 CS0103:引用 ClientID 的行上的当前上下文中不存在名称“ControlName”
。
是否有另一种方法可以将 ID 传递给 Javascript 函数?
I have Telerik RadGrid with a custom edit form. In my edit form there is a RadDatePicker to which I have added a custom footer template containing a 'Today' button.
In the OnClick event of the button I call a Javascript function which takes the control ID to set the selected date.
However, because the control is inside the edit form there is no variable created for it and the compiler throws an error when I try getting the client ID.
The RadDatePicker is declared with:
<telerik:RadDatePicker ID="ControlName" runat="server" SelectedDate='<%# Bind("Field") %>'>
<Calendar ID="Calendar1" runat="server">
<FooterTemplate>
<div style="width: 100%; text-align: center; background-color: Gray;">
<input id="Button1" type="button" value="Today" class="button"
onclick="GoToToday('<%= ControlName.ClientID %>')" />
</div>
</FooterTemplate>
</Calendar>
</telerik:RadDatePicker>
The error I get is CS0103: The name 'ControlName' does not exist in the current context
on the line referencing the ClientID.
Is there another way in which to get the ID to pass to the Javascript function?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我使用 RadAjaxPanel 包装 Telerik RadGrid,然后在绑定事件的服务器端代码中,我使用 Ajax 面板设置一些 Javascript 变量:
然后,我向 DatePicker 添加了一个客户端事件处理程序:
ClientEvents-OnPopupOpening ="AddButtonClickEvent"
然后,该页面包含以下 Javascript,以使用 jQuery 绑定单击事件处理程序:
一切都按预期工作。
I resorted to wrapping the Telerik RadGrid with a RadAjaxPanel and then in the server side code for the bind event I used the Ajax panel to set some Javascript variables:
I then added a client side event handler to the DatePicker:
ClientEvents-OnPopupOpening="AddButtonClickEvent"
The page then includes the following Javascript to bind the click event handler using jQuery:
And it all works as expected.
尝试:
您还可以在 page_load 事件中设置事件处理程序。
Try:
You could also set the event handler in the page_load event.
也许表单上控件的 ClientEvents-OnLoad 事件会有帮助?它不是很漂亮,但似乎很有效。
首先在页面上制作脚本
然后在aspx中,用于控制您需要在客户端获取的编辑表单,
添加这样的事件
因此,当您按下网格上的编辑或插入按钮时,将显示表单 - 将设置 javascript 中的全局变量。您可以使用它来操作文本框。唯一的问题是,如果您想操作所有控件,则表单上的每个控件都需要这样的事件=(
Maybe ClientEvents-OnLoad event of controls on form will help? It's not very beautiful, but seems to work.
First make script on page
Then in aspx, for control on edit form that you need to get on client,
add event like this
So, when you press edit or insert button on grid, and form will be shown - global variable in javascript will be set. And you can use it to manipulate textbox. Only problem is that you need event like this for each control on form, if you want to manipulate all controls =(