简体   繁体   中英

LinkButton onclick event in repeater in updatepanel

I can use Click event in a repeater, repeater is in an updatepanel. I am using div as trigger that is trying to click to LinkButton.

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()");
}

Getting Errors in a Browser:

Image (async)
_updatePanel @ ScriptResource.axd?d…YI5aZ0&t=3d6efc1f:5
_scriptIncludesLoadComplete @ ScriptResource.axd?d…YI5aZ0&t=3d6efc1f:5
(anonymous) @ ScriptResource.axd?d…qOX341&t=3d6efc1f:5
(anonymous) @ 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
(anonymous) @ ScriptResource.axd?d…qOX341&t=3d6efc1f:5
(anonymous) @ ScriptResource.axd?d…qOX341&t=3d6efc1f:5
completed @ ScriptResource.axd?d…qOX341&t=3d6efc1f:5
_onReadyStateChange @ ScriptResource.axd?d…qOX341&t=3d6efc1f:5
XMLHttpRequest.send (async)
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
(anonymous) @ ScriptResource.axd?d…qOX341&t=3d6efc1f:5
(anonymous) @ VM7570:1

Do you have any idea? How can i use javascript click event without any problem. if user clicks to the div, i would like to click to the link button.

Updatepanel > Repeater > Div > LinkButton

I recreated the Repeater (I think, it would really help if you posted that also next time).

<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>

The problem probably is that you are changing the ID of the LinkButton. So remove lnk_product.ID = "lnk_product_" + (e.Item.ItemIndex + 1); . You don't need to change it. Then it will work.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM