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

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:

(Markup)

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

share|improve this question
add comment

1 Answer

up vote 5 down vote accepted

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, 
                 title:'Druckansicht', 
                 width:640, 
                 height:400
              } 
SP.UI.ModalDialog.showModalDialog(options);

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

share|improve this answer
    
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 '12 at 13:51
add comment

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.