In this article I will explain how to set AJAX UpdatePanel Triggers i.e. PostBackTrigger or AsyncPostBackTrigger for Button or LinkButton placed in GridView within AJAX UpdatePanel.
If you try to add PostBackTrigger or AsyncPostBackTrigger for such Button or LinkButton which is placed inside GridView, you will get following error.
A control with ID 'Button1' could not be found for the trigger in UpdatePanel.
 
 
HTML Markup
The HTML Markup consists of ASP.Net GridView with 2 LinkButtons placed inside an AJAX UpdatePanel.
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
    <ContentTemplate>
        <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false">
            <Columns>
                <asp:BoundField DataField="FruitName" HeaderText="Fruit Name" />
                <asp:TemplateField>
                    <ItemTemplate>
                        <asp:LinkButton ID="lnkPartial" runat="server" Text="Partial PostBack" OnClick="PartialPostBack" />
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField>
                    <ItemTemplate>
                        <asp:LinkButton ID="lnkFull" runat="server" Text="Full PostBack" OnClick="FullPostBack" />
                    </ItemTemplate>
                </asp:TemplateField>
            </Columns>
        </asp:GridView>
    </ContentTemplate>
</asp:UpdatePanel>
 
 
Namespaces
You will need to import the following namespace.
C#
using System.Data;
 
VB.Net
Imports System.Data
 
 
Populating the GridView
I have created a dynamic DataTable with some dummy data and it has been bound to the GridView control in Page Load event.
Note: You can learn more about this technique in my article Create DataTable dynamically and bind to GridView in ASP.Net
C#
protected void Page_Load(object sender, EventArgs e)
{
    if (!this.IsPostBack)
    {
        DataTable dt = new DataTable();
        dt.Columns.Add("FruitName");
        dt.Rows.Add("Apple");
        dt.Rows.Add("Mango");
        dt.Rows.Add("Banana");
        dt.Rows.Add("Orange");
        dt.Rows.Add("Pineapple");
        GridView1.DataSource = dt;
        GridView1.DataBind();
    }
    this.RegisterPostBackControl();
}
 
VB.Net
Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
    If Not Me.IsPostBack Then
        Dim dt As New DataTable()
        dt.Columns.Add("FruitName")
        dt.Rows.Add("Apple")
        dt.Rows.Add("Mango")
        dt.Rows.Add("Banana")
        dt.Rows.Add("Orange")
        dt.Rows.Add("Pineapple")
        GridView1.DataSource = dt
        GridView1.DataBind()
    End If
    Me.RegisterPostBackControl()
End Sub
 
 
Registering the Button Control as PostBack Trigger
Inside the Page Load event described earlier, I have made a call to RegisterPostBackControl method which is looping through the GridView Rows and registering the lnkFull LinkButton as PostBack Trigger so that when this LinkButton is clicked a Full PostBack occurs.
Note: It is very important to place the RegisterPostBackControl method outside Not IsPostBack condition otherwise it will work only for first time and then stop working.
Many sites suggest use of OnRowDataBound or OnDataBinding events but these methods also work only for first time if the GridView is bound in Not IsPostBack condition and hence I came up with this technique.
C#
private void RegisterPostBackControl()
{
    foreach (GridViewRow row in GridView1.Rows)
    {
        LinkButton lnkFull = row.FindControl("lnkFull") as LinkButton;
        ScriptManager.GetCurrent(this).RegisterPostBackControl(lnkFull);
    }
}
 
VB.Net
Private Sub RegisterPostBackControl()
    For Each row As GridViewRow In GridView1.Rows
        Dim lnkFull As LinkButton = TryCast(row.FindControl("lnkFull"), LinkButton)
        ScriptManager.GetCurrent(Me).RegisterPostBackControl(lnkFull)
    Next
End Sub
 
 
Click events for Buttons for testing Full PostBack and Partial PostBack
For the two LinkButtons inside the GridView, I have added click event handlers for displaying JavaScript alert message box so that we can view the difference in working of both the buttons.
C#
protected void PartialPostBack(object sender, EventArgs e)
{
    string fruitName = ((sender as LinkButton).NamingContainer as GridViewRow).Cells[0].Text;
    string message = "alert('Partial PostBack: You clicked " + fruitName + "');";
    ScriptManager.RegisterClientScriptBlock(sender as Control, this.GetType(), "alert", message, true);
}
 
protected void FullPostBack(object sender, EventArgs e)
{
    string fruitName = ((sender as LinkButton).NamingContainer as GridViewRow).Cells[0].Text;
    string message = "alert('Full PostBack: You clicked " + fruitName + "');";
    ClientScript.RegisterClientScriptBlock(this.GetType(), "alert", message, true);
}
 
VB.Net
Protected Sub PartialPostBack(sender As Object, e As EventArgs)
    Dim fruitName As String = TryCast(TryCast(sender, LinkButton).NamingContainer, GridViewRow).Cells(0).Text
    Dim message As String = "alert('Partial PostBack: You clicked " & fruitName & "');"
    ScriptManager.RegisterClientScriptBlock(TryCast(sender, Control), Me.GetType(), "alert", message, True)
End Sub
 
Protected Sub FullPostBack(sender As Object, e As EventArgs)
    Dim fruitName As String = TryCast(TryCast(sender, LinkButton).NamingContainer, GridViewRow).Cells(0).Text
    Dim message As String = "alert('Full PostBack: You clicked " & fruitName & "');"
    ClientScript.RegisterClientScriptBlock(Me.GetType(), "alert", message, True)
End Sub
 
Assign PostBack Trigger (Full PostBack) for LinkButton inside GridView within AJAX UpdatePanel in ASP.Net
 
Demo
 
Downloads