SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

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";


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
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

You can do this by using a method similar to the one described here

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;
                var frame = $(".ms-dlgFrame");
                frame.attr("name", frame.attr("id"));
                var frameParent = frame.parent();
                var html = frame[0].outerHTML;
                var form = $("<form action='" + formUrl + "' method='post' target='" + frame.attr("name") + "'><input type='hidden' name='args' value='" + JSON.stringify(args) + "' /><input type='submit' /></form>");
            }, '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

Your Answer


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.