开发者

On-Click Event fires first time, but not subsequent times

I have a LinkButton which fires an OnClick event to update some Labels; however, after the first firing of OnClick, it won't fire again when I click another (or the same) LinkButton which runs the same OnClick event. (It's a list of people, each a LinkButton, and clicking on one brings up their details)

If I leave the page a few minutes, it will work again, almost as if whatever was preventing OnClick firing timed-out. Of course, this won't be any use to the users!

This is my ASP.NET code for the LinkButtons (encapsulated in a DataList):

<asp:DataList ID="DataList1" runat="server" DataKeyField="AdmissionNumber">
        <ItemTemplate>
            <asp:CheckBox ID="CheckBox" runat="server" OnCheckedChanged="Checkbox_CheckedChanged" ViewState="true"/>
            <asp:LinkButton ID="LinkButton" runat="server" OnClick="LinkButton_OnClick">
                <asp:HiddenField ID="hfAdmissionNumber" Value='<%# Eval("AdmissionNumber") %>' runat="server"/>
                <asp:Label ID="CalledLabel" runat="server" Text='<%# Eval("Called") %>' />&nbsp;
                <asp:Label ID="SurnameLabel" runat="server" Text='<%# Eval("Surname") %>' />
            </asp:LinkButton><br /><br />
        </ItemTemplate>
</asp:DataList>

In the Page_Load event in the C# code behind, the following populates the DataList:

connection.Open();
SqlDataReader reader = command.ExecuteReader();
DataList1.DataSource = reade开发者_JAVA百科r;
DataList1.DataBind();
connection.Close();

And this is the OnClick event:

protected void LinkButton_OnClick(object sender, EventArgs e)
{
    LinkButton l = (LinkButton)sender;
    HiddenField hfv = (HiddenField)l.Parent.FindControl("hfAdmissionNumber");
    using (SqlConnection connection = new SqlConnection("Data Source=pastonmis01\\inform;Initial Catalog=2009;Integrated Security=True"))
    {
        using (SqlCommand command = new SqlCommand("xProcSportNotParticipantDetails",connection))
        {
            connection.Open( );
            command.CommandType = System.Data.CommandType.StoredProcedure;
            command.Parameters.AddWithValue("@AdmissionNumber", Int32.Parse(hfv.Value));
            SqlDataReader reader = command.ExecuteReader();
            reader.Read();
            lTitle.Text = reader.GetValue(0).ToString();
            lSurname.Text = reader.GetValue(1).ToString();
            lForename.Text = reader.GetValue(2).ToString();
            lCalled.Text = reader.GetValue(3).ToString();
            lDoB.Text = reader.GetValue(4).ToString().Substring(0,10);
            lSex.Text = reader.GetValue(5).ToString();
            reader.Close();
        }
        connection.Close();
    }
}

All the connections work, the data is retrieved, etc, so everything except the OnClick firing works. I've done a search of the internet and found this seems to have been a long-standing problem since the first ASP.NET, but there is no solution for ASP.NET 3.5. Does anyone know what causes this, or where I might be going wrong?


Try giving OnClientClick="Page_BlockSubmit=false" for your link button

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜