What I need to do is to open an aspx-page in a modal dialog when the user clicks on a asp:button.

Currently I'm doing this:


<asp:Button runat="server" ID="TestButton" Text="Add Category" PostBackUrl="javascript:OpenPopUpPageWithTitle('_layouts/Customer/AddCat.aspx', RefreshOnDialogClose, 600, 400,'Add new Category')"/>

It's working, but what I need is to provide the ID of SPContext.Current.ListItem from the "source aspx" to the new one opened in the dialog.

To add params like {Site} to the PostBackUrl seems not to work.

Do you have any tips for me?

1 Answer 1


you can open the modal dialog without a postback something like:

<asp:Button runat="server ID="TestButton" onclick="javascript:...."

The second point is that you dont need to put the whole path to the application page into the url. When you open the modal dialog from an application page AddCat.aspx would be enough.

But how do I do this.

First I build a javascript method. I dont like to declare my function in the code. Maybe I need a variable to. So I declare a function.. maybe:

function OpenAddCat() {
    // do something

The next step. When I need the path to the sitecollection I do the following in the function:

var siteCollectionUrl = '<asp:Literal runat="server" Text="<%$SPUrl:~SiteCollection/%>" />';

The next step. I want to open the modal dialog. I would do it in this way:

var urlSite = "AddCat.aspx;
var options = { 
                 url: urlSite, 

The button should look like this:

 <asp:Button ID="TestButton" Text="AddCat" runat="server" onclick="javascript: OpenAddCat();" />

I hope this could be a solution for you.

best regards

  • Hi, perhaps it is obvious for all of you but I don't know where to put the javascript functions?! Into the .ascx of my vwp? I want to use a visual webpart in the "retriever-modal" which gets a value from my first webpart which is on top of newform/editform.aspx of a list and I just don't get the clue at the moment. Would be great to have a tutorial for this whole action, though.
    – Dominik
    Dec 19, 2012 at 13:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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