Alpha Video Training
Results 1 to 6 of 6

Thread: Setting Session Variables with AJAX callbacks, timeouts needed??

  1. #1
    Member
    Real Name
    Luke
    Join Date
    Dec 2011
    Location
    Northern Virginia, USA
    Posts
    174

    Default Setting Session Variables with AJAX callbacks, timeouts needed??

    I have an action button on a grid that first does a AJAX callback which calls a function I wrote to set a session variables (I do not know any other way of doing it at this point). Then the next action is to load a A5W pages with a grid component and a bunch of custom Xbasic code. The problem I am having is the grid on the new page has a filter which uses the session variable set on the AJAX callback but it is not propagating properly. The Xbasic code on the new page uses the session variable also and that is getting the session variable fine. If I click refresh in the browser the grid filter works fine which makes me think it is a timing issue. Also after I have done this once and I click another account number from the original grid the new page grid will show the last account number, then if I refresh the page the new account number will show up.

    I have tried using the setTimeout function in my AJAX callback but it does not seem to be honoring it because if i set a ridiculously long timeout like seconds it still instantly loads the page. See below code.

    Here is a screenshot of the action button event for the AJAX callback:
    action_button.PNG

    My AJAX callback global helper function code used to set the session variable.
    Code:
    'Global Helper Function, Set account session variable
    function Ghelp_SetAcctSessVar as c (e as p)
    	dim session.svAccountNum as n
    	session.svAccountNum = e._currentRowDataNew.ACCOUNT_NUM
    	
    	'debug(1)
    
    	Ghelp_SetAcctSessVar="setTimeout(,50);"
    end function
    UPDATE: I just updated alpha 5 to the newest release and the session variable is not set at all unless I use a separate button just for assigning the session variable then another button to redirect.

  2. #2
    Volunteer Moderator Peter.Greulich's Avatar
    Real Name
    Peter Greulich
    Join Date
    Apr 2000
    Location
    Boston, MA
    Posts
    11,654

    Default Re: Setting Session Variables with AJAX callbacks, timeouts needed??

    You are right - it's a timing issue. Remember, your ajax callback (xbasic function) returns JavaScript. The trick is to use the JS to open the a5w page. That way your session var gets set, and then the page opens afterwards.

    BTW: You can also set session vars in most grid (xbasic) events, which may or may not be appropriate in your case.

  3. #3
    "Certified" Alphaholic
    Real Name
    Frank Bicknell
    Join Date
    Feb 2010
    Location
    39.1915° N, 84.4348° W
    Posts
    2,467

    Default Re: Setting Session Variables with AJAX callbacks, timeouts needed??

    I used to set session variables like you. See video M41. This should solve your problem.
    Win 10 64 Development, Win 7 64 WAS 11-1, 2, Win 10 64 AA-1,2, MySql, dbForge Studio The Best MySQL GUI Tool IMHO. http://www.devart.com/dbforge/mysql/studio/

  4. #4
    Volunteer Moderator Peter.Greulich's Avatar
    Real Name
    Peter Greulich
    Join Date
    Apr 2000
    Location
    Boston, MA
    Posts
    11,654

    Default Re: Setting Session Variables with AJAX callbacks, timeouts needed??

    Frank,

    M41 - way cool. I haven't watched so many of these videos, that's a good one. Thanks

  5. #5
    "Certified" Alphaholic
    Real Name
    Frank Bicknell
    Join Date
    Feb 2010
    Location
    39.1915° N, 84.4348° W
    Posts
    2,467

    Default Re: Setting Session Variables with AJAX callbacks, timeouts needed??

    My pleasure. In case you have not already figured it out you can get a value from the search part using 'S' instead of 'G'.
    Win 10 64 Development, Win 7 64 WAS 11-1, 2, Win 10 64 AA-1,2, MySql, dbForge Studio The Best MySQL GUI Tool IMHO. http://www.devart.com/dbforge/mysql/studio/

  6. #6
    Member
    Real Name
    Luke
    Join Date
    Dec 2011
    Location
    Northern Virginia, USA
    Posts
    174

    Default Re: Setting Session Variables with AJAX callbacks, timeouts needed??

    Thanks for the responses Peter & Frank!

    Peter, I was messing around with trying to assign a session variable in the grid OnGridInitalize event of a grid on the same page of the button that does a page redirect. The problem is the is filtered by account number from a link on another page. I am setting an account number session variable which means I have to have access to the grid data to get this account number, the OnGridInitalize event does not seem to have access to grid data. Is there a way to grab the account number that is passed in when linking the grid and set that to the session var?

    It is probably just best to show a picture of the setup, this should help a ton explain what is going on..
    sessionVarTest.PNG

    As for using the button to set the session variable, putting the redirect in the AJAX callback did the trick! A target page is passed in on the ajax callback.
    Code:
    function Ghelp_SetAcctSessVar as c (e as p)
    	dim session.svAccountNum as n
    	session.svAccountNum = e._currentRowDataNew.ACCOUNT_NUM
    
    	Ghelp_SetAcctSessVar="setTimeout(function delayer(){window.location = '" + e.target + "'},100);"
    end function
    Frank, Thanks for the video but this only works when loading a grid. When opening a webpage instead of a grid the "set session variables" button is not present
    Last edited by LukeS; 02-09-2012 at 04:55 PM.

Similar Threads

  1. Setting session variables.... whats the optimal/ideal place to declare?
    By leetv in forum Application Server Version 10 - Web/Browser Applications
    Replies: 8
    Last Post: 03-27-2014, 07:31 AM
  2. setting session variables from grid fields
    By phannon in forum Application Server Version 10 - Web/Browser Applications
    Replies: 8
    Last Post: 06-18-2012, 10:17 PM
  3. Setting e.newValues with protected session variables
    By Scholin in forum Application Server Version 9 - Web/Browser Applications
    Replies: 8
    Last Post: 08-04-2011, 11:29 AM
  4. Trouble with Session Variables, AJAX Callbacks, and AJAX Popup Windows
    By njw1314 in forum Application Server Version 10 - Web/Browser Applications
    Replies: 7
    Last Post: 07-20-2011, 11:53 PM
  5. Session variable timeouts
    By rcr211 in forum Application Server Version 10 - Web/Browser Applications
    Replies: 0
    Last Post: 02-10-2011, 04:06 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •