Aspose.Form for .NET allows its users to load InfoPath forms with multiple views. Aspose.Form for .NET provides two possible ways to switch between different views of a form with multiple views.
Using Rules
You can add a new rule and set the action as “Switch views”.
Using Code
You can assign the name of a view to the ActiveViewName property and that view will be activated if the name will be correct.
Aspose.Form for .NET also provides ActiveViewChanged event that can be handled to perform some actions when active view will be changed. For example, you can load data in the active view from an XML file.
The example below uses two buttons to activate first or second view of a multi view form and ActiveViewChanged event is also handled to load the data from an XML file into the active view.
Example
[C#]
protected void XmlFormView1_ActiveViewChanged(object sender, EventArgs e)
{
string filePath;
//Checking the active view and loading the related form data
if (XmlFormView1.ActiveViewName == "View1")
{
filePath = Server.MapPath(xmlFileView1);
}
else
{
filePath = Server.MapPath(xmlFileView2);
}
using (System.IO.StreamReader reader = new System.IO.StreamReader(Server.MapPath(xmlFile)))
{
//Reading and assigning the data of XML file to FormControl
XmlFormView1.XmlDataString = reader.ReadToEnd();
}
}
protected void btnView1_Click(object sender, EventArgs e)
{
XmlFormView1.ActiveViewName = "View1";
}
protected void btnView2_Click(object sender, EventArgs e)
{
XmlFormView1.ActiveViewName = "View2";
}
[VB.NET]
Protected Sub XmlFormView1_ActiveViewChanged(ByVal sender As Object, ByVal e As EventArgs)
Dim filePath As String
'Checking the active view and loading the related form data
If XmlFormView1.ActiveViewName = "View1" Then
filePath = Server.MapPath(xmlFileView1)
Else
filePath = Server.MapPath(xmlFileView2)
End If
Using reader As System.IO.StreamReader = New System.IO.StreamReader(Server.MapPath(xmlFile))
'Reading and assigning the data of XML file to FormControl
XmlFormView1.XmlDataString = reader.ReadToEnd()
End Using
End Sub
Protected Sub btnView1_Click(ByVal sender As Object, ByVal e As EventArgs)
XmlFormView1.ActiveViewName = "View1"
End Sub
Protected Sub btnView2_Click(ByVal sender As Object, ByVal e As EventArgs)
XmlFormView1.ActiveViewName = "View2"
End Sub