获取DetailsView和UpdatePanel之间的控件ClientID/UniqueID
我想知道如何获取Detailsview 控件EditItemTemplate 元素内控件的ClientID/UniqueID,以及当DetailsViews 更改为编辑模式且DetailsView 位于AJAX UpdatePanel 内时。如果没有 UpdatePanel,在 PostBack 期间我可以获得 ClientID 的控制权,但现在有了 UpdatePanel。
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:DetailsView ID="DetailsView1" runat="server" DataSourceID="SqlDataSource1" AllowPaging="true" AutoGenerateEditButton="true">
<Fields>
<asp:TemplateField>
<EditItemTemplate>
<asp:CheckBox runat="server" ID="chkboxTest" Text="CHECKBOX" />
</EditItemTemplate>
</asp:TemplateField>
</Fields>
</asp:DetailsView>
</ContentTemplate>
</asp:UpdatePanel>
如您所见,EditItemTemplate 包含一个复选框控件。因此,当“详细信息视图”更改为“编辑”模式时,我尝试获取此复选框的 ClientID。我需要这个值来处理 Javascript。
捕获事件ChangingMode/ChangedMode不起作用; chkbox 为空:
void DetailsView1_ModeChanged(object sender, EventArgs e)
{
if (DetailsView1.CurrentMode == DetailsViewMode.Edit)
{
var chkbox = DetailsView1.FindControl("chkboxTest"); // <== is null
}
}
也许我使用了错误的事件?有人可以给我一个关于这个的提示吗?谢谢。
I like to know how to get the ClientID/UniqueID of a control inside a Detailsview controls EditItemTemplate element and when DetailsViews changing to Edit mode and DetailsView is inside a AJAX UpdatePanel. Without UpdatePanel, during PostBack I can get the ClientID's control, but now with an UpdatePanel.
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:DetailsView ID="DetailsView1" runat="server" DataSourceID="SqlDataSource1" AllowPaging="true" AutoGenerateEditButton="true">
<Fields>
<asp:TemplateField>
<EditItemTemplate>
<asp:CheckBox runat="server" ID="chkboxTest" Text="CHECKBOX" />
</EditItemTemplate>
</asp:TemplateField>
</Fields>
</asp:DetailsView>
</ContentTemplate>
</asp:UpdatePanel>
As you see, the EditItemTemplate contains a Checkbox control. So i'm trying to get the ClientID of this checkbox when Detailsview is changing to the Edit mode. I need this value for handling Javascript.
Catching the events ChangingMode/ChangedMode doesn't work; chkbox is null:
void DetailsView1_ModeChanged(object sender, EventArgs e)
{
if (DetailsView1.CurrentMode == DetailsViewMode.Edit)
{
var chkbox = DetailsView1.FindControl("chkboxTest"); // <== is null
}
}
Maybe i'm using the wrong event? Someone can give me a tip about this? Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
好的,最好的办法是为 OnDataBound 实现一个处理程序,然后执行以下操作:
Ok, the best thing to do is implement a handler for OnDataBound, then do something like:
void DetailsView1_ModeChanged(对象发送者,EventArgs e)
{
if (DetailsView1.CurrentMode == DetailsViewMode.Edit)
var chkbox = DetailsView1.Rows[0].FindControl("chkxboxTest"); // <== 为空
?
加粗的文本是拼写错误吗
我没有太多使用DetailsView,但使usre Rows[0] 不是标题行,行下是否有任何单元格?就像网格视图一样。
更新:我假设您想要做的就是在用户更新项目后捕获控件?将事件处理程序分配给 OnItemUpdating 并尝试以下操作:
void DetailsView1_ModeChanged(object sender, EventArgs e)
{
if (DetailsView1.CurrentMode == DetailsViewMode.Edit)
var chkbox = DetailsView1.Rows[0].FindControl("chkxboxTest"); // <== is null
}
Is the enboldened text a typo?
I haven't had much use of the DetailsView but make usre Rows[0] is not a header row, and are there any Cells under the rows? Like the GridView.
UPDATE: I'm assuming all you want to do is capture the control after the user has updated the items? Assign an event handler to OnItemUpdating and try the following: