i have a datalist,it's itemtemplate is inside an updatepanel,in which i have a button whose click event is not being fired

plz help

Hi.
Can you show the example code?.

button click in the following code is not working:
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:DataList ID="DataList1" runat="server">
<ItemTemplate>
<asp:UpdatePanel ID="UpdatePanel1" runat="server" ChildrenAsTriggers="true">
<ContentTemplate>
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" />
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="Button1" EventName="Click" />
</Triggers>
</asp:UpdatePanel>
</ItemTemplate>
</asp:DataList>
</div>
</form>
</body>
</html>

Try this.

<asp:ScriptManager ID="ScriptManager1" runat="server">
        </asp:ScriptManager>
        <asp:DataList ID="DataList1" runat="server" OnItemCommand="GetDetails">
            <ItemTemplate>
            <asp:UpdatePanel ID="UpdatePanel1" runat="server" ChildrenAsTriggers="true">
                <ContentTemplate>
                    <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
                    <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
                    <asp:Button ID="Button1" runat="server" CommandName="Test" Text="Button" />
                </ContentTemplate>
                <Triggers>
                <asp:AsyncPostBackTrigger ControlID="Button1" />
                </Triggers>
            </asp:UpdatePanel>
            </ItemTemplate>
        </asp:DataList>

in the source code create a function like this

protected void GetDetails(object sender, DataListCommandEventArgs e)
    {
        if (e.CommandName == "Test")
        {
            ((TextBox)e.Item.FindControl("TextBox1")).Text = "Hi";
        }
    }

This last funcion will write the text Hi to the TextBox1 that belong to the current row clicked.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.