updatepanel中的中继器中的LinkBut​​ton onclick事件

时间:2018-10-27 08:35:35

标签: javascript c# asp.net onclick click

我可以在转发器中使用Click事件,转发器在更新面板中。我正在使用div作为试图单击LinkBut​​ton的触发器。

protected void rpt_product_ItemCreated(object sender, RepeaterItemEventArgs e)
{
    HtmlGenericControl div_product = (HtmlGenericControl)e.Item.FindControl("div_product");
    LinkButton lnk_product = (LinkButton)e.Item.FindControl("lnk_product");
    lnk_product.ClientIDMode = ClientIDMode.Static;
    lnk_product.ID = "lnk_product_" + (e.Item.ItemIndex + 1);
    div_product.Attributes.Add("onclick", "document.getElementById('" + lnk_product.ClientID + "').click()");
}

在浏览器中获取错误:

  

图片(异步)
  _updatePanel @ ScriptResource.axd?d ... YI5aZ0&t = 3d6efc1f:5
  _scriptIncludesLoadComplete @ ScriptResource.axd?d…YI5aZ0&t = 3d6efc1f:5
  (匿名)@ ScriptResource.axd?d ... qOX341&t = 3d6efc1f:5
  (匿名)@ ScriptResource.axd?d ... qOX341&t = 3d6efc1f:5
  _loadScriptsInternal @ ScriptResource.axd?d ... YI5aZ0&t = 3d6efc1f:5
  _nextSession @ ScriptResource.axd?d…YI5aZ0&t = 3d6efc1f:5
  loadScripts @ ScriptResource.axd?d…YI5aZ0&t = 3d6efc1f:5
  _onFormSubmitCompleted @ ScriptResource.axd?d…YI5aZ0&t = 3d6efc1f:5
  (匿名)@ ScriptResource.axd?d ... qOX341&t = 3d6efc1f:5
  (匿名)@ ScriptResource.axd?d ... qOX341&t = 3d6efc1f:5
  已完成@ ScriptResource.axd?d…qOX341&t = 3d6efc1f:5
  _onReadyStateChange @ ScriptResource.axd?d ... qOX341&t = 3d6efc1f:5
  XMLHttpRequest.send(异步)
  executeRequest @ ScriptResource.axd?d ... qOX341&t = 3d6efc1f:5
  executeRequest @ ScriptResource.axd?d ... qOX341&t = 3d6efc1f:5
  invoke @ ScriptResource.axd?d ... qOX341&t = 3d6efc1f:5
  _onFormSubmit @ ScriptResource.axd?d…YI5aZ0&t = 3d6efc1f:5
  _doPostBack @ ScriptResource.axd?d ... YI5aZ0&t = 3d6efc1f:5
  (匿名)@ ScriptResource.axd?d ... qOX341&t = 3d6efc1f:5
  (匿名)@ VM7570:1

你有什么主意吗?我该如何使用javascript click事件而不会出现任何问题。如果用户单击div,我想单击链接按钮。

Updatepanel>中继器> Div> LinkBut​​ton

1 个答案:

答案 0 :(得分:0)

我重新创建了Repeater(我认为,如果您下次也发布它,那真的很有帮助)。

let p // a primitive

p = 1
p += 1
p -= 1
p %= 1
p *= 1

问题可能是您正在更改LinkBut​​ton的ID。因此,删除<asp:UpdatePanel ID="UpdatePanel1" runat="server"> <ContentTemplate> <asp:Repeater ID="rpt_product" runat="server" OnItemCreated="rpt_product_ItemCreated"> <ItemTemplate> <div id="div_product" runat="server"> <asp:LinkButton ID="lnk_product" runat="server" OnClick="lnk_product_Click">LinkButton</asp:LinkButton> Div Contents </div> </ItemTemplate> </asp:Repeater> </ContentTemplate> </asp:UpdatePanel> 。您不需要更改它。然后它将起作用。