0

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

2
Contributors
3
Replies
5
Views
7 Years
Discussion Span
Last Post by jbisono
0

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>

0

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.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.