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 got a question, How to add popap window to Sharepoint by the code. I tried many thinks, but they could be block by web browsers. I must find that want unblock by web browsers.

share|improve this question
    
What version of SharePoint? –  Dave Wise Oct 24 '12 at 20:18
add comment

1 Answer

up vote 3 down vote accepted

Grzegorz,

This is a simplest form of SharePoint 2010 Modal Dialog, using SP.Dialog class!

function test() { 
        //debugger; 
        SP.UI.ModalDialog.showModalDialog({ 
            url: "/Lists/Announcements/NewForm.aspx", 
            title: "Add item", 
            allowMaximize: true, 
            showClose: true, 
            width: 800, 
            height: 600, 
           dialogReturnValueCallback: silentCallback 
       }); 
   }; 

   function silentCallback(dialogResult, returnValue) { 
   } 

   function refreshCallback(dialogResult, returnValue) { 
       SP.UI.ModalDialog.RefreshPage(SP.UI.DialogResult.OK); 
   }

This is same dialog which opens when you add new item to a list, or edit any item! You can provide any url in SP Dialog Options!

More reading here

Edited:

Try this:

LiteralControl controlLit = new LiteralControl();
controlLit.Text = "<a onclick='javascript:test();' href='#'>click here</a>";
 e.Cell.Controls.Add(controlLit);
share|improve this answer
2  
It is Javascript, you don't have this option in .cs file.. You can write this in a Visual Web Part or a Content Editor Web Part, and call test() function on a button click or anywhere! –  Arsalan Adam Khatri Oct 24 '12 at 21:04
1  
you can inject the <script> in Content Editor Web Part, and then call the function by making <a onclick="javascript:test();" href="#">click here to open popup<\a> –  Arsalan Adam Khatri Oct 24 '12 at 21:17
1  
Yes, here you can add a new Literal Control and set popup as mentioned above! –  Arsalan Adam Khatri Oct 24 '12 at 21:21
1  
updated the answer for you! –  Arsalan Adam Khatri Oct 24 '12 at 21:33
1  
Post another question for this :D, I will give the answer there! –  Arsalan Adam Khatri Oct 24 '12 at 22:01
show 11 more comments

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.