How to automatic Switch the View of the Form - InfoPath Dev
in

InfoPath Dev

How to automatic Switch the View of the Form

Last post 02-12-2007 01:08 PM by JoeyL. 5 replies.
Page 1 of 1 (6 items)
Sort Posts: Previous Next
  • 12-24-2006 12:36 AM

    How to automatic Switch the View of the Form

    Hi,

    I have a Form Template with mutiple views, one is "View 1" and the second one named "View 2", the "View 1" is my default view, and it is published to the SharePoint Server with Forms Server deployed with it. I can open the form via browser, here's my problem: the first time I opened the form, it is "View 1", but after the submition, the next time I open it, I want it switch to the "View 2", I've tried using the SwitchView method, but there seems to have some problem.


    Best Regards,

    LinFeng
  • 12-24-2006 09:34 PM In reply to

    Re: How to automatic Switch the View of the Form

    Hello LinFeng and Welcome to Forums,
    Have you gone through this tutorialhttp://www.infopathdev.com/howto/tutorials/default.aspx?i=b5613773df374e42a0dddc22acb21d8e

    Hope this helps!
  • 12-25-2006 01:47 AM In reply to

    Re: How to automatic Switch the View of the Form

    quote:
    Originally posted by shailaja

    Hello LinFeng and Welcome to Forums,
    Have you gone through this tutorialhttp://www.infopathdev.com/howto/tutorials/default.aspx?i=b5613773df374e42a0dddc22acb21d8e

    Hope this helps!




    Hi Shailaja,

    I'm appreciate your reply on this, yes, I have read this tutorial already before I post this question.
    I'm trying to switch the view of the InfoPath Form which opened in browser, because the aspx page use the XmlFormView control to show the InfoPath Form, so I wonder whether there is any method to switch the view.
    I also know the SwitchView method can't be use in the OnLoad event, so I did a test on this by using a button on the aspx page to call this method by the OnClick event, but when I debug this in Visual Studio, a “NullReferenceException was unhandled by user code” exception occur, it says “Object reference not set an instance of an object”.I also tried the thisXDocument.ViewInfos["My View Name"].IsDefault = true; in order to Change the Default View when the form is opened in the browser, but infact there's no "IsDefault" property provided for me to set the Default View, it still no work.
    I don't know reason for these problem and how to fix them, I really appreciate for your guys help.

    Thanks in advance!
  • 12-25-2006 08:44 PM In reply to

    • Shiva
    • Top 25 Contributor
    • Joined on 04-15-2005
    • India
    • Posts 694

    Re: How to automatic Switch the View of the Form

    Hi LinFeng,

    We should not use thisXDocument.ViewInfos["My View Name"].IsDefault = true statement in onClick event. If we try debugging on this statement in other than onLoad event we didn#%92t get the IsDefault property. We need to write this statement in onLoad event only. You can write below code in your onLoad event for your requirement.
    if(thisXDocument.IsNew)
    {
    //Form open in first time
    thisXDocument.ViewInfos["View 1"].IsDefault = true;
    }
    else
    {
    //After submitting the form
    thisXDocument.ViewInfos["View 2"].IsDefault = true;

    }
  • 12-25-2006 09:41 PM In reply to

    Re: How to automatic Switch the View of the Form

    Hi Shiva,

    Thanks so much for your reply.
    Maybe I didn't describe the question clearly.
    I did an experiment, I created a custom aspx page using the Visual Studio and drag the XmlFormView control to the page, after that, I insert the URL of the form template, the code of this aspx page would add a line of code like this:

    <cc1:xmlformview id="XmlFormView2" runat="server" editingstatus="Editing" height="250px" width="100%" xsnlocation="http://servername/formlibrary/Forms/template.xsn" OnInitialize="LoadForm"></cc1:xmlformview>

    and then, in the code behind, I add the LoadForm function, I tried to use the

    XmlFormView2.XmlForm.ViewInfos["ViewName"].IsDefault=true;

    to set the default view when the form is opened via browser, but, there's no "IsDefault" statement provided.

    So, the OnLoad view switch seems not gonna work...

    And then, I tried the OnClick event, I add a button to the aspx page, and use the button's OnClick Event to call a function named "ChangeView" to change the view, the code is below:

    protected void ChangeView(object sender, EventArgs e)
    {
    XmlFormView2.XmlForm.ViewInfos.SwitchView("View2");
    }


    when I debug, in the aspx page, I click the button, an NullReferenceException occur, this really puzzle me, is there anything I can do to fix these problems?
  • 02-12-2007 01:08 PM In reply to

    • JoeyL
    • Not Ranked
    • Joined on 02-12-2007
    • Posts 1

    Re: How to automatic Switch the View of the Form

    Has there been any development on this? I am having a similar problem.

    XmlFormView1.XmlForm.ViewInfos.SwitchView("Address"); in a button click event gives an object error.
Page 1 of 1 (6 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.