1

Here´s my predicament. I have an Assignment.aspx custom application page. On this page I´m calling a web service to fetch an assignment object from the SQL server. This object is fairly big and takes about a second to fetch. I am then saving this assignment object in the httpcontext to use it to display information on the different controls in the page.
One of these controls displays the list of tasks that the assignment contains, and each list item will open a dialog pointing to the task page when clicked.

The issue I´m having is that I need the assignment object to be available on the task page, and would like to avoid fetching it again so the performance does not take a hit.

The question is: how do I pass the object from the assignment page to the task page that´s being opened inside a dialog?

What I have tried

  1. Saving the assignment object in a session variable This works, but I´d like to avoid it if possible. On one hand I´d need a bunch of extra logic to ensure the right object is in the session. On the other hand, well, session state is disabled by default so I´d like to keep it like that if possible
  2. Serializing the object and passing it in the url. No go. One of the attributes of the assignment object is an ICollection so I get an error when trying to serialize.
  3. Trying to read from Page.PreviousPage. but it is null, I´m guessing because it is being opened inside a dialog

Any ideas?

Update I managed to serialize server side, fetch the variable client side, pass it in the modal arguments and fetch it inside the modal. However, I need it server side again, and when I try to post it back to the server I get a 500, I´m guessing because the variable is just too big (using an ajax call that works just fine when I post a simple string)

1

I was facing a similar issue recently. In my case I passed the variables in the options.args:

var options = SP.UI.$create_DialogOptions();
options.url = formUrl;

var data = {};
data.YourVariable1 = yourVariable1;
data.YourVariable2 = yourVariable2;
var dataAsString = JSON.stringify(data);
options.args = dataAsString;

options.dialogReturnValueCallback = function(result){
    switch(result){
        case SP.UI.DialogResult.invalid: 
            break;
        case SP.UI.DialogResult.cancel:
            //form closed
        case SP.UI.DialogResult.OK: 
            //form submitted
        }
};

SP.UI.ModalDialog.showModalDialog(options);

And then fetched the variables inside the form:

var data = JSON.parse(window.frameElement.dialogArgs);
var yourVariable1 = data.YourVariable1;
var yourVariable2 = data.YourVariable2;
  • So, I fetch the assignment variable server side. When I try to access it in the client side to stringify it the page crashes spectacularly. It complains that the type of the assignment variable is defined in an assembly that´s not referenced, which is a lie since the assembly is referenced and I am using the type all over the place. – Ritx May 16 '17 at 16:41
  • Hmm, that's weird. Don't know what to advise as in my case it's all client side, just two different contexts... – Gintas K May 17 '17 at 7:49
  • Follow up: I managed to serialize server side, fetch the variable client side, pass it in the modal arguments and fetch it inside the modal. However, I need it server side again, and when I try to post it back to the server I get a 500, I´m guessing because the variable is just too big. – Ritx May 17 '17 at 8:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.