Answer the question
In order to leave comments, you need to log in
Strange session variable behavior on multiple Ajax requests?
Hello.
I've run into a problem that I don't know how to resolve.
I won't post the code yet. First, I will describe the problem in the general case.
There is a static class manager. With which grid view works. This class has a property that works with the session. This session is needed to store the entries selected by the checkbox in the grid view. There is some two-step functionality and that's where you need to remember the session. When a one-time check / uncheck is made, an Ajax request goes to some record and the method of adding / deleting a value in the session is triggered, and then everything is OK (the collection is stored in the session). But if you click on the checkbox five or ten times in a row and generate a lot of consecutive Ajax requests, then the session will have either zero or some one (most often the first) value (if several checkboxes are selected). I can't understand why this is happening. It is also impossible to debug in the debug in the studio, since the debug catches the first Ajax request and works with it, the rest of the requests do not get there.
Maybe someone came across something similar. Please help, friends.
UPDATE:
Friends. I've localized the problem, but still haven't figured out what the problem is.
I bring the code.
Variable names are shortened so as not to give exact code, but the logic is completely preserved. I think it will be clear.
There is this code
protected void btnAction_Click(object sender, ImageClickEventArgs e)
{
var trs = MlEManager.MlEItems.OfType<tcT>();
CreateSCtion(trs, userId, date, comment, sCenterId);
}
public static SomeType CreateSCtion(IEnumerable<tcT> trs, Guid userId, DateTime date, string comment, Guid? sCenterId = null)
{
var result = SomeType.GetInstance();
//try
//{
var firstT = trs.First();
var trsCountTemp = trs.Count();
var ction = new tcCtion
{
UId = userId,
CtionBeginTime = date,
CtionEndTime = date,
CtionId = firstT.LocId,
SProviderAddressId = sCenterId,
STypeId = SType.All[SType.SAdjustment].STypeId
};
CManager.CContext.Ctions.AddObject(ction);
ction.FId = ction.Loc.FId;
if (ction.SProviderAddressId.HasValue)
ction.Com = ction.SCenter.Com;
StringBuilder sb = new StringBuilder();
foreach (var t in trs)
{
CManager.CContext.CtedTrs.AddObject(new CtedT { Ction = ction, TId = t.TId, VirtualMMPlier = 1 });
sb.AppendLine(t.Id + "||||||||");
}
if (!String.IsNullOrEmpty(comment))
CManager.CContext.tcCtionCnts.AddObject(new CtionComment
{
Ction = ction,
Date = DateTime.Now,
UserId = CManager.CUser.UserId,
CtionCommentTypeEnum = 1,
CtionCommentText = comment
});
CManager.CContext.SaveChanges();
result.Data = ction;
throw new Exception("top=" + trsCountTemp.ToString() + "========" + sb.ToString() + "======== bottom=" + trs.Count().ToString());
//}
//catch (Exception exc)
//{
//result.AddError(exc.Message);
//}
return result;
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question