Switch view when host xmlformview in aspx

Source: Internet
Author: User

When you place xmlformview on your own ASPX page, you may need to switch the view logic. For example, when a process is bound to a form library, the formserviceformtask page of quickflow switches the view based on the _ currentview field in taskfields of the task activity.

Xmlformview provides two methods:

Xmlviewer. xmlform. viewinfos. switchview ("approval ")

Xmlviewer. xmlform. viewinfos. Initial = xmlviewer. xmlform. viewinfos ["approval"]

But these two methods are either incorrect or useless.

Find the most reasonable way is to use JS switch, refer to the http://www.moss2007.be/blogs/vandest/archive/2008/10/10/forms-server-xmlformview-and-setting-the-initialview-on-load.aspx

However, this will cause secondary page refresh.

No way to use reflect for analysisCode, Find the method for setting the view with reflection:

1) For each point2007

Void switchview12 (string viewname) {If (string. isnullorempty (viewname) throw new argumentnullexception ("viewname"); // check view exist. object viewinfo = NULL; try {viewinfo = This. xmlviewer. xmlform. viewinfos [viewname];} catch {} If (viewinfo = NULL) {Throw new notsupportedexception ("view doesn't exist:" + viewname); return ;} // use reflection to control this. xmlviewer. xmlform. document. currentviewname system. reflection. propertyinfo pdocument = This. xmlviewer. xmlform. getType (). getproperty ("document", system. reflection. bindingflags. nonpublic | system. reflection. bindingflags. instance); If (pdocument = NULL) {Throw new nullreferenceexception ("can't get property xmlform. document "); return;} object objdoc = pdocument. getvalue (this. xmlviewer. xmlform, null); If (objdoc = NULL) {Throw new nullreferenceexception ("can't get value: xmlform. document "); return;} // objdoc. currentview = objdoc. solution. views [this. _ xmlformhost. viewinfos. default. name]; system. reflection. propertyinfo pcurrentview = objdoc. getType (). getproperty ("currentview"); // debug ("currentview:" + pcurrentview); system. reflection. propertyinfo psolution = objdoc. getType (). getproperty ("solution"); // debug ("psolution:" + psolution); object objsolution = psolution. getvalue (objdoc, null); // debug ("objsolution:" + objsolution); idictionary views = objsolution. getType (). getproperty ("views", system. reflection. bindingflags. nonpublic | system. reflection. bindingflags. instance ). getvalue (objsolution, null) as idictionary; // debug ("views:" + views); object v = views [viewname]; // debug ("V: "+ V); pcurrentview. setvalue (objdoc, V, null );}

This method is called in the oninitlized method.

2) For each point2010

The above method should also work on 2010, but 2010 provides a more convenient method: xmlformview. defaultview,

Bool switchview14 (string viewname)
{
VaR pdefaultview = xmlviewer. GetType (). getproperty ("defaultview"); // It can only be set before databind

// The defaultview attribute may be a public method, so reflection is unnecessary. However, the code is implemented in section 2007, so reflection must be used.
If (pdefaultview = NULL)
Return false;
Pdefaultview. setvalue (xmlviewer, viewname, null );
Return true;
}

This method is different: it cannot be called in the oninitlized method, and must be called before xmlformview databind.

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.