0
ListIDFromQueryString = '{08.....3-d...-....-....-........ce47}';

I want to use this value as the parameter (with a different name) in a link to open a modal dialog box.

$('#my-element').after('<a 'href="http://MySite.aspx?...some URL" '
+'onclick="javascript:NewItem2(event, &quot;http://MySite.aspx?SessionID=' + SessionIDFromQueryString + '&amp;ListID=' + ListIDFromQueryString + '&quot;);javascript:return false;" target="_self">Add new item</a></td></tr>'

I want the link to open a modal dialog instead of sending me to a new page but for some values between the curly braces, a new page opens instead of the modal dialog.

ListID={..some-value..}

If I erase the last '7', for example, e new modal dialog appears.

  • Can you append "IsDialog=1" at the end of Query String parameters and see what happens – Arsalan Adam Khatri Apr 23 '14 at 8:48
  • Now the URL looks like this but it's still not working: http://MySite/Lists/MyList/NewForm.aspx?SessionID=92&ListID={SomeNumber}&IsDialog=1&Source=http%3A%2F%2F... – MicSokoli Apr 23 '14 at 8:53
1

your code is giving me a headacke ;)

use the JS object model!

SP.UI.ModalDialog.showModalDialog(options);

example:

aspx:

this is a button, you could have some other form of input type.

<input type="button" value="Ok" onclick="opendialogNow(); return false;" />

the above calls this js method below:

<script type="text/javascript">
SP.SOD.executeOrDelayUntilScriptLoaded(getUsername, "SP.js");


function opendialogNow() {
            var options = {
                url: "http://mysite:8437/Pages/home.aspx",  
                width: 600,
                height: 300,
                title: "My Dialog",
                allowMaximize: true,
                showClose: true
            };
            SP.UI.ModalDialog.showModalDialog(options);
}

</script>

have the JS within the main page, it will create a sharepoint dialog box for you ;) . You have two options, either you can use the url or html within options.... url is the full url to the page you want to show, the html is the html you want to show that is on the page(use html id or full html code)!

so for you, you want to pass the url value id of the list?

pass the custom url value:

aspx, passing the varible values:

<input type="button" value="Ok" onclick="opendialogNow(SessionIDFromQueryString,ListIDFromQueryString ); return false;" />

Js, build the url here

<script type="text/javascript">
SP.SOD.executeOrDelayUntilScriptLoaded(getUsername, "SP.js");


function opendialogNow(SessionIDFromQueryString ,ListIDFromQueryString ) {

            var url = "http://MySite.aspx?SessionID=" + SessionIDFromQueryString + "ListID=" + ListIDFromQueryString;

            var options = {
                url: url,  
                width: 600,
                height: 300,
                title: "My Dialog",
                allowMaximize: true,
                showClose: true
            };
            SP.UI.ModalDialog.showModalDialog(options);
}

</script>

the url might be wrongly built but i it just needs a bit of tweaking and ull get it working!

  • This worked. The reason my code looked like that is because I copied the markup of the "Add New Item" link from another page so my button would look better. Now that I improved it, it works well. Thank you. – MicSokoli Apr 23 '14 at 12:27
  • no problem happy to help :) – Ali Jafer Apr 23 '14 at 14:21

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.