How to fire server-side methods with jQuery
- by Nasser Hajloo
I have a large application and I'm going to enabling short-cut key for it. I'd find 2 JQuery plug-ins (demo plug-in 1 - Demo plug-in 2) that do this for me. you can find both of them in this post in StackOverFlow
My application is a completed one and I'm goining to add some functionality to it so I don't want towrite code again.
So as a short-cut is just catching a key combination, I'm wonder how can I call the server methods which a short-cut key should fire?
So How to use either of these plug-ins, by just calling the methods I'd written before?
Actually How to fire Server methods with Jquery?
You can also find a good article here, by Dave Ward
Update: here is the scenario. When User press CTRL+Del the GridView1_OnDeleteCommand so I have this
protected void grdDocumentRows_DeleteCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
try
{
DeleteRow(grdDocumentRows.DataKeys[e.Item.ItemIndex].ToString());
clearControls();
cmdSaveTrans.Text = Hajloo.Portal.Common.Constants.Accounting.Documents.InsertClickText;
btnDelete.Visible = false;
grdDocumentRows.EditItemIndex = -1;
BindGrid();
}
catch (Exception ex)
{
Page.AddMessage(GetLocalResourceObject("AProblemAccuredTryAgain").ToString(), MessageControl.TypeEnum.Error);
}
}
private void BindGrid()
{
RefreshPage();
grdDocumentRows.DataSource = ((DataSet)Session[Hajloo.Portal.Common.Constants.Accounting.Session.AccDocument]).Tables[AccDocument.TRANSACTIONS_TABLE];
grdDocumentRows.DataBind();
}
private void RefreshPage()
{
Creditors = (decimal)((AccDocument)Session[Hajloo.Portal.Common.Constants.Accounting.Session.AccDocument]).Tables[AccDocument.ACCDOCUMENT_TABLE].Rows[0][AccDocument.ACCDOCUMENT_CREDITORS_SUM_FIELD];
Debtors = (decimal)((AccDocument)Session[Hajloo.Portal.Common.Constants.Accounting.Session.AccDocument]).Tables[AccDocument.ACCDOCUMENT_TABLE].Rows[0][AccDocument.ACCDOCUMENT_DEBTORS_SUM_FIELD];
if ((Creditors - Debtors) != 0)
labBalance.InnerText = GetLocalResourceObject("Differentiate").ToString() + "?" + (Creditors - Debtors).ToString(Hajloo.Portal.Common.Constants.Common.Documents.CF) + "?";
else
labBalance.InnerText = GetLocalResourceObject("Balance").ToString();
lblSumDebit.Text = Debtors.ToString(Hajloo.Portal.Common.Constants.Common.Documents.CF);
lblSumCredit.Text = Creditors.ToString(Hajloo.Portal.Common.Constants.Common.Documents.CF);
if (grdDocumentRows.EditItemIndex == -1)
clearControls();
}
Th other scenario are the same. How to enable short-cut for these kind of code (using session , NHibernate, etc)