Hi Tevin,
You need to use UpdatePanel to prevent the page refresh on cancel button click.
Place the Repeater inside UpdatePanel.
Please refer below sample.
HTML
<asp:ScriptManager runat="server" />
<asp:UpdatePanel runat="server">
<ContentTemplate>
<asp:Repeater ID="rpAllCovidHistory" runat="server">
<HeaderTemplate>
<table class="table table-striped table-bordered table-hover table-condensed" border="1">
<tr>
<th id="CovidHistoryIDHead" runat="server" visible="false">No</th>
<th>Name</th>
<th style="text-align: center;">Captured Date</th>
<th>Clock No</th>
<th>Quarantine</th>
<th>Test Result</th>
<th>Test Date</th>
<th>Result Date</th>
<th>Start Date</th>
<th>Return Date</th>
<th>Other</th>
<th></th>
<th></th>
<th></th>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr runat="server" id="employeeInfo">
<td id="lblCovidHistory" runat="server" visible="false">
<asp:Label Text='<%#DataBinder.Eval(Container.DataItem, "CovidHistoryID")%>' runat="server" ID="lblCovidHistoryID" />
</td>
<td>
<asp:Label Text='<%#DataBinder.Eval(Container.DataItem, "EmployeeName")%>' runat="server" ID="lblEmployeeName" />
</td>
<td>
<asp:Label Text='<%# Eval("CaptureDate", "{0: dd/MM/yyyy}")%>' runat="server" ID="Label1" />
</td>
<td>
<asp:Label Text='<%#DataBinder.Eval(Container.DataItem, "ClockNo")%>' runat="server" ID="lblClockNo" />
</td>
<td>
<asp:Label Text='<%#DataBinder.Eval(Container.DataItem, "Quarantine")%>' runat="server" ID="lblQuarantine" />
</td>
<td>
<asp:Label Text='<%#DataBinder.Eval(Container.DataItem, "TestResult")%>' runat="server" ID="lblTestResult" />
</td>
<td>
<asp:TextBox ID="txtTestDate" Visible="true" class="form-control" BorderStyle="None" BackColor="#F9F9F9" Enabled="false" Text='<%# Eval("TestDate", "{0: dd/MM/yyyy}")%>' runat="server"></asp:TextBox>
</td>
<td>
<asp:TextBox ID="txtResultDate" Visible="true" class="form-control" BorderStyle="None" BackColor="#F9F9F9" Enabled="false" Text='<%# Eval("ResultDate", "{0: dd/MM/yyyy}")%>' runat="server"></asp:TextBox>
</td>
<td>
<asp:TextBox ID="txtFromDate" Visible="true" class="form-control" BorderStyle="None" BackColor="#F9F9F9" Enabled="false" Text='<%# Eval("FromDate", "{0: dd/MM/yyyy}")%>' runat="server"></asp:TextBox>
</td>
<td>
<asp:TextBox ID="txtToDate" Visible="true" class="form-control" BorderStyle="None" BackColor="#F9F9F9" Enabled="false" Text='<%# Eval("ToDate", "{0: dd/MM/yyyy}")%>' runat="server"></asp:TextBox>
</td>
<td>
<asp:Label Width="300px" Text='<%#DataBinder.Eval(Container.DataItem, "Other")%>' runat="server" ID="lblOther" />
</td>
<td>
<asp:LinkButton ID="lbtnEdit" CssClass="btn btn-sm btn-success" CommandName="Edit" CommandArgument='<%# DataBinder.Eval(Container.DataItem, "CovidHistoryID") %>' OnClick="Edit" runat="server">Edit</asp:LinkButton>
</td>
<td>
<asp:LinkButton ID="lbtnSave" CssClass="btn btn-sm btn-success" Enabled="false" runat="server">Save</asp:LinkButton>
</td>
<td>
<asp:LinkButton ID="lbtnCancel" CssClass="btn btn-sm btn-success" Enabled="false" runat="server" OnClick="Cancel">Cancel</asp:LinkButton>
</td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
</ContentTemplate>
</asp:UpdatePanel>
Namespace
C#
using System.Data;
VB.Net
Imports System.Data
Code
C#
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
DataTable dt = new DataTable();
dt.Columns.AddRange(new DataColumn[11]{ new DataColumn("CovidHistoryID"),
new DataColumn("EmployeeName"),
new DataColumn("CaptureDate"),
new DataColumn("ClockNo"),
new DataColumn("TestDate"),
new DataColumn("Quarantine"),
new DataColumn("TestResult"),
new DataColumn("ResultDate"),
new DataColumn("FromDate"),
new DataColumn("ToDate"),
new DataColumn("Other")
});
dt.Rows.Add(100, "Rahul", "2022-01-25 12:00:00", 1, "2022-01-27 12:00:00", "1 Week", "2022-01-28 12:00:00", "2022-01-29", "2022-01-27", "2022-02-07", "Other");
rpAllCovidHistory.DataSource = dt;
rpAllCovidHistory.DataBind();
}
}
protected void Edit(object sender, EventArgs e)
{
RepeaterItem item = (sender as LinkButton).NamingContainer as RepeaterItem;
(item.FindControl("lbtnCancel") as LinkButton).Enabled = true;
}
protected void Cancel(object sender, EventArgs e)
{
(sender as LinkButton).Enabled = false;
}
VB.Net
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
If Not Me.IsPostBack Then
Dim dt As DataTable = New DataTable()
dt.Columns.AddRange(New DataColumn(10) {New DataColumn("CovidHistoryID"), New DataColumn("EmployeeName"), New DataColumn("CaptureDate"), New DataColumn("ClockNo"),
New DataColumn("TestDate"), New DataColumn("Quarantine"), New DataColumn("TestResult"), New DataColumn("ResultDate"), New DataColumn("FromDate"),
New DataColumn("ToDate"), New DataColumn("Other")})
dt.Rows.Add(100, "Rahul", "2022-01-25 12:00:00", 1, "2022-01-27 12:00:00", "1 Week", "2022-01-28 12:00:00", "2022-01-29", "2022-01-27", "2022-02-07", "Other")
rpAllCovidHistory.DataSource = dt
rpAllCovidHistory.DataBind()
End If
End Sub
Protected Sub Edit(ByVal sender As Object, ByVal e As EventArgs)
Dim item As RepeaterItem = TryCast((TryCast(sender, LinkButton)).NamingContainer, RepeaterItem)
TryCast(item.FindControl("lbtnCancel"), LinkButton).Enabled = True
End Sub
Protected Sub Cancel(ByVal sender As Object, ByVal e As EventArgs)
TryCast(sender, LinkButton).Enabled = False
End Sub