Attach server side click event handler for HTML Table TR (Row) in ASP.Net

Last Reply on Feb 10, 2014 12:03 AM By Azim

Posted on Feb 09, 2014 11:36 PM

I hv a tr inside repeater i want a onclick function on tr which all some method in code behind.?

You are viewing reply posted by: Azim on Feb 10, 2014 12:03 AM.
Posted on Feb 10, 2014 12:03 AM Modified on on Feb 10, 2014 12:03 AM

You have  use  IPostBackEventHandler interface for this

This Way:


<form id="form1" runat="server">
    <asp:Repeater ID="rptDemo" runat="server">
                <tr onclick="<%= _jsPostBackCall %>;">
                        <asp:Label Text='<%# Eval("Alphabets") %>' runat="server" />
        <asp:Literal ID="litMessage" runat="server" />
    <asp:Button Text="Save" runat="server" />



public partial class TableRowEvent : System.Web.UI.Page, IPostBackEventHandler
    protected String _jsPostBackCall;

    protected void Page_Load(object sender, EventArgs e)
        // "myTr" will be passed as an argument to RaisePostBackEvent method
        _jsPostBackCall = ClientScript.GetPostBackEventReference(this, "myTr");
        if (!this.IsPostBack)
            DataTable dt = new DataTable();
            dt.Columns.Add("Alphabets", typeof(string));
            this.rptDemo.DataSource = dt;

    public void RaisePostBackEvent(string eventArgument)
        switch (eventArgument)
            case "myTr":

            // you can add other controls that need postback processing here

                throw new ArgumentException();

    private void HandleTrClick()
        litMessage.Text = "Tr clicked.";

Thank You.