2

I have virtually no experience with web development but now I need to create a web part for SharePoint 2010 and I am stuck.

The web part is supposed to find all content types derived from folder content type and create buttons that would open the upload form for that content type. This means that the buttons must be generated dynamically depending on the content types of each library.

I've managed to create my web part but I can't get it to display the form correctly. If i simply say that each button is a hyperlink, the form is opened in a new window and doesn't close when I am done with the form. To get to open in a popup like a normal upload form I use the following code:

    button.OnClientClick = "javascript:" +
                                            " var options = {" +
                                            " url: '" + Url + "'," +
                                            " title: 'Create Folder'," +
                                            " allowMaximize: true," +
                                            " showClose: true," +
                                            " width: 800," +
                                            " height: 600" +
                                            " };" +
                                            "SP.UI.ModalDialog.showModalDialog(options);";

What I am doing is assigning a JavaScript code to a previously defined LinkButton in my .cs file. In fact all of my code is in the .cs file.

What happens when this is run is that the form opens and I am able to create a new folder. When I close it however, the popup doesn't close. Instead I am left with a blank popup that can't be closed even when clicking the X in the upper right hand corner. I have to reload the page to get the form popup to go away.

So how do I close this form or open it in such a way that I don't run into problems. If the solution is to combine C# with some client side code please be very specific because I have no clue how this is done.

2
  • Why don't you dump all required client code into a User Control (ASCX) which you can reference from the server side code?
    – James Love
    Jan 24, 2013 at 20:22
  • Because I don't know how to do it. Remebr I don't know anything about this. When I created a web part project in Visual Studio, it created a visualWebPart1UserControl.ascx file. IS that the one you are talking about? How do I dump the code here and how do I reference it in the .cs file?
    – Eugene
    Jan 24, 2013 at 21:03

1 Answer 1

4

I'm not sure if I understood you correctly. But when I want to open form I use asp:HyperLink and in codebehind I set NavigateUrl like this:

hyperLink.NavigateUrl = "javascript:SP.UI.ModalDialog.ShowPopupDialog('" + url + "')";

If you want to open form (edit, view, etc) use copyutil - it can generate the exact url address for you: http://weblogs.asp.net/jan/archive/2008/02/26/copyutil-aspx-a-little-sharepoint-gem.aspx

1
  • Yes this is exactly what I have been trying to do. Thank you very much.
    – Eugene
    Jan 28, 2013 at 19:10

Your Answer

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

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