I am using Telerik Grid control in which i am displaying list of records along with Update and Delete functionality.
Now i want to show confirmation box when deleting records so that user doesnt accidentally delete the record.
So here is my approach:
1)I have one master page i.e is MyMaster.Master which contains one common client side events for confirmation box which i would be using sweetalert for that:
function DeleteData(Id) {
var ajaxManager = null;
var action = 'Remove';
ajaxManager = $find("ctl00_cphMain_RadAjaxManager2");
var arg = action + "," + Id; //Remove,1(1 indicates id of record to remove from grid)
ajaxManager.ajaxRequest(arg);This line will fire below method.
}
2)I have created 1 Parentpage from which all of my page would be inherited and on this page my RadAjaxManager2_AjaxRequest
would reside so that i dont have to pollute my every page with this method and this method will be responsible to handle my delete functionality on every page:
In this Method i will pass name of my delete method to fire.For Eg:Remove1
public class ParentPage : RadAjaxPage
{
protected void RadAjaxManager2_AjaxRequest(object sender, AjaxRequestEventArgs e)
{
var stringArray = e.Argument.Split(",".ToCharArray());//[0]="Remove1",[1]=id of record to delete
RemoveRecord( stringArray[0], stringArray[1]);
}
}
3)My Page that is Abc.aspx where i would place my delete functionality to remove record from database and bindgridview:
<telerik:RadAjaxManager ID="RadAjaxManager2" runat="server" OnAjaxRequest="RadAjaxManager2_AjaxRequest">
<AjaxSettings>
<telerik:AjaxSetting AjaxControlID="RadAjaxManager2">
<UpdatedControls>
<telerik:AjaxUpdatedControl ControlID="Grid1" />
</UpdatedControls>
</telerik:AjaxSetting>
</AjaxSettings>
</telerik:RadAjaxManager>
<ItemTemplate>
<asp:ImageButton runat="server" ID="Remove1" Text="Delete" OnClientClick='<%# Eval("Id", "javascript:return DeleteData(\"{0}\");") %>' />
</ItemTemplate>
public partial class Abc : ParentPage
{
protected void Page_Load(object sender, EventArgs e)
{
}
private void RemoveRecord( buttonId, recordId)
{
if(buttonId== "Remove1")
{
//code to delete record with id of recordId
//Bind grid view again to display latest records after performing deletion.
}
}
}
All this is working perfect but the problem is as we all know that when we inherit child page from parent page then we call parent page method from child page method but here in my case this is opposite that is i am calling my RemoveRecord method from parent page and that is i think it is inappropriate.
So i want to overcome this.How to properly configure my delete functionality???