The content you're reading is getting on in years
This post is on the older side and its content may be out of date.
Be sure to visit our blogs homepage for our latest news, updates and information.
[This post is part of the developer's manual preview published on this blog. You can find temporary TOC here.]
Since Views are “disconnected” in a way and one switches them my navigating and not postback, this raises the issue of state. There is no ViewState and there is no ControlState. The question is how you pass information from one View to another.
New backend architecture works with two parameters:
Let’s start with demonstrating some samples to see how to pass information between two views.
*** NOTE ***
Passing parameters slightly differs between Views based on ViewModeControl and ViewModeUserControl.
*** END NOTE ***
SAMPLE 1: Creating a command for a View and passing parameter that can be converted to GUID with it
Guid product1Id = new Guid("DFC2058E-C458-486c-A243-577528C51AA8"); |
this.EditProduct1.NavigateUrl = CreateHostViewCommand<ProductEditView>(product1Id.ToString()); |
SAMPLE 2: Accessing received parameter which can be converted to GUID
Guid productId = this.DataItemId; |
The ability to automatically parse parameter as a GUIDs, does not mean that you can only pass GUIDs as parameters. We can send any kind of serializable data through parameters. Here is an example of sending a simple string text.
SAMPLE 3: Creating a command and passing a general type of string with it
NavigateHostCommand<ProductPreviewView>("Good morning!"); |
Now, on the View that will receive this parameter you can access its value as follows.
SAMPLE 4: Accessing the value of passed parameter which cannot be converted to a GUID
string message = HttpContext.Current.Request.QueryString[base.ParameterKey]; |
Notice, how we are using the ParameterKey as a QueryString key. By default the value of ParameterKey is “Param”, which means that in the url parameter will be transferred as follows:
www.mysite.com/sitefinity/admin/modules.aspx? module=StoreModule&route=StoreControlPanel.ProductsView.ProductEditView&Param=dfc2058e-c458-486c-a243-577528c51aa8
Alternatively, you can decide to override the ParameterKey property on your Views and replace it with something more specific and user friendly, such as “ProductID”.
*** WARNING ***
When overriding ParameterKey, make sure you override it on both View that sends parameter and the one that receives it. Otherwise, the receiving View will not be able to pick out the value of parameter from the QueryString.
*** END WARNING ***
SAMPLE 5: Sending ParentId parameter to a view
Guid product1Id = new Guid("DFC2058E-C458-486c-A243-577528C51AA8"); |
Guid storeId = new Guid("8BB08866-E0AE-42c6-8DC3-6C59FF9039DD"); |
this.ViewProduct1.NavigateUrl = CreateHostViewCommand<ProductPreviewView>(product1Id.ToString(), storeId.ToString()); |
Built in feature of GUID parameter being automatically converted to Guid works for ParentId parameter as well. Let’s take a look at how would a receiving View access the values of the two parameters we have sent.
SAMPLE 6: Retriving the values of Param and ParentId on the receiving View
Guid productId = this.DataItemId; |
Guid storeId = this.ParentId; |
As for the Parameter, where one is able to override ParameterKey and change its value to something else, the same possibility exists for ParentId. One can override ParentIdKey property, which default value is “ParentID” and change it to something more specific, such as “Store”.
*** WARNING ***
When overriding ParentIdKey, make sure you override it on both View that sends parameter and the one that receives it. Otherwise, the receiving View will not be able to pick out the value of parameter from the QueryString.
*** END WARNING ***
Generally speaking, when navigating between Views, methods such as CreateHostViewCommand, NavigateHostViewCommand etc. will have overloads that accept Parameter and ParentId. By specifying those values, you will be sending the parameters to the receiving View.
View all posts from The Progress Team on the Progress blog. Connect with us about all things application development and deployment, data integration and digital business.
Let our experts teach you how to use Sitefinity's best-in-class features to deliver compelling digital experiences.
Learn MoreSubscribe to get all the news, info and tutorials you need to build better business apps and sites
Progress collects the Personal Information set out in our Privacy Policy and the Supplemental Privacy notice for residents of California and other US States and uses it for the purposes stated in that policy.
You can also ask us not to share your Personal Information to third parties here: Do Not Sell or Share My Info
We see that you have already chosen to receive marketing materials from us. If you wish to change this at any time you may do so by clicking here.
Thank you for your continued interest in Progress. Based on either your previous activity on our websites or our ongoing relationship, we will keep you updated on our products, solutions, services, company news and events. If you decide that you want to be removed from our mailing lists at any time, you can change your contact preferences by clicking here.