Question

In my web part I use the create_DialogOptions JS function to create a new aspx site as a dialog box. That works fine. Now I would like to have access to the custom properties from the web part.

I tried it like this: public ProjectName.WebpartName.WebpartName(Class) WebPartProperty { get; set; } Now if I try to access to the properties, I get a null reference. (I new its senseless, but I would have a try :)) I don’t know how I could do this. Is it any way possible to get access to those properties?

It would be nice if someone could help me.

Edit: I think I could do it, with the consumer, provider model. I will have a try. If there is a better solution, let me know.

Edit2: Well, the consumer, provider model doesn't work . I can't connect the aspx site.

Add some code:

@tim-gabrhel You are right! Here some code:

I have created a visual web part and added some personal properties to the web part. For example hostname:

private string _hostname = string.Empty;
[WebBrowsable(true), WebDescription("Hostname"), WebDisplayName("Hostname"),
Personalizable(PersonalizationScope.Shared), Category("Webpart Settings")]              
public string hostname 
{
    get 
    {
        return _hostname;
    }
    set 
    {
        _hostname = value;
    }        
}

In the

public partial class WebPartNameUserControl : UserControl
{
…
}

class, I call public WebPartName WebPartProperty { get; set; } and get access to the properties.

I use the create_DialogOptions() JS function to create a new dialog window, where the user could insert some stuff.

function ShowDialog() {
    var options = SP.UI.$create_DialogOptions();
    options.url = "/_layouts/ProjectName/Dialog.aspx";
    options.width = 600;
    options.height = 300;
    SP.UI.ModalDialog.showModalDialog(options);
}

Now I need access from the dialog to the web part property. How could I get the hostname from the properties?

I hope my problem is now more understandable .

Edit 4:

I found a way, how I could access to the custom properties. I add at the Page_Load() the properties to a session[""], after that, I could use the values in my dialog.

session["test"] = propertyOne;
string value = (string)session["test"];

Are they any disadvantages for that solution? A normal provider, consumer model is not possible?

Greetz

Was it helpful?

Solution

Another alternative would be to use the SP.UI.Dialog.args object which would allow us to pass arbitrary properties into the dialog. This could be inturn retrieved from the opened page using the SP.UI.ModalDialog.get_childDialog().get_args() property.

Please read this detailed post to find how its implemented - http://www.chaholl.com/archive/2010/11/17/using-the-dialog-framework-in-sharepoint-2010.aspx

OTHER TIPS

This post tells:

For a practical example of the deployment and use of pages for modal dialog boxes, including how to pass information to the modal dialog box, see the Full-Trust Proxy Reference Implementation. For more information about using the SharePoint client object model in JavaScript, see ECMAScript Object Model Reference on MSDN.

Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top