Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I have a button, that opens Modal Dialog using SP.UI.ModalDialog.showModalDialog(options) Options contains field "args".

I can read this "args" using window.frameElement.dialogArgs in javascript code of Dialog Page.

But i need to read this args in codebehind in methods like OnLoad, or OnPreRender.

I tried to save args to hiddenValue, but javascript is executing after OnPreRender.

share|improve this question

2 Answers 2

You can do this by using a method similar to the one described here http://social.msdn.microsoft.com/Forums/en-us/iewebdevelopment/thread/126fcea8-c28b-49ce-ad49-65884ffabeb6

Basically you open up an iframe pointing to about:blank. Then you create a new form that posts to the page you want to post to, along with a input value containing your data and targets your blank iframe. Then you submit the form.

Here's a sample function that does just that. Note that because of a bug with ie and dynamically renamed iframes, you have to remove and add the iframe back.

var openModalAndPostData = function (url, args) {
            var formUrl = url+ "?IsDlg=1";               
            ExecuteOrDelayUntilScriptLoaded(function () {
                var options = SP.UI.$create_DialogOptions();
                options.url = "about:blank";
                options.width = 990;
                options.height = 560;
                options.args = args;
                options.dialogReturnValueCallback = closeCallback;
                SP.UI.ModalDialog.showModalDialog(options);
                var frame = $(".ms-dlgFrame");
                frame.attr("name", frame.attr("id"));
                var frameParent = frame.parent();
                var html = frame[0].outerHTML;
                frame.remove();
                frameParent.append(html);
                var form = $("<form action='" + formUrl + "' method='post' target='" + frame.attr("name") + "'><input type='hidden' name='args' value='" + JSON.stringify(args) + "' /><input type='submit' /></form>");
                $('body').append(form);
                form.submit();
                form.remove();
            }, 'sp.js');
        }

If you use this, then you can access your modal's args in the codebehind using "Request.Form["args"]

share|improve this answer

Instead of passing those arguments using the "args" object, you can append them in the QueryString in the Url of the page. Something like this:

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

options.title = "My Dialog Title";
options.url = "/_layouts/DialogPage.aspx?Arg1=value&Arg2=value&Arg3=value";

SP.UI.ModalDialog.showModalDialog(options);

And then in the code behind, you can use this to get the value of the args:

string valueOfArg1 = Page.Request.QueryString["Arg1"];
string valueOfArg2 = Page.Request.QueryString["Arg2"];
share|improve this answer
1  
yes, but length of my 'args' can be more then 255 and i think that`s why this method will not work in this case –  Alexey Aug 27 '12 at 6:35
    
If that's the case and you need to pass large amounts of data between pages, then use Session State and retrieve the session state data on the modal page. –  Fox Feb 12 '13 at 8:21

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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