Question

I've created a custom webpart that shows me some details of a dossier. I've added a DossierID property like this:

public Guid DossierId { get; set; }

This identifies the dossier from which I want to see the details.

I also have a BCS list with dossiers. I've placed my custom webpart on the dispform of this list. I can retrieve the current ID with

HttpContext.Current.Request.QueryString["ID"];

But I don't like to do that because then I can't use my webpart in a place where I don't have an ID in the querystring.

Is there a way to bind the ID used in the querystring of dispform.aspx to the property of my custom webpart?

Was it helpful?

Solution

I'd create a property for the Id in the webpart, which allows the user putting the web-part on a page to specify the id to use.

Where you need the Id in the code you could do the check to see if the Id property was set, then use that otherwise use the one from the QueryString and if that's missing fail.

Then you could add the webpart to dispform.aspx without setting the property and it'll work as before.

Adding it to another page you could set the Id in the properties.

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