Problems with changing views using UpdatePanel inside Multiview

Last post 07-01-2008 2:03 PM by thduttonuk. 10 replies.

Sort Posts:

  • Problems with changing views using UpdatePanel inside Multiview

    02-28-2007, 4:34 PM
    • Member
      17 point Member
    • cnordvik
    • Member since 09-28-2006, 7:17 PM
    • Posts 13

    Hi!


    I am having some troble figuring out how this is supposed to work. My code looks like this:


    <asp:UpdatePanel ID="pnlMeldinger" runat="server" UpdateMode="Conditional">
      <ContentTemplate>
     ...
      </ContentTemplate>
      <Triggers>
        <asp:AsyncPostBackTrigger ControlID="btnOK" />
      </Triggers>
    </asp:UpdatePanel>

    <asp:Button ID="btnOK" runat="server" Text="Send" OnClick="btnOK_Click" />
      <asp:UpdateProgress ID="progress" runat="server">
        <ProgressTemplate>
          <asp:Label ID="lblProgress" runat="server" Text="BUSY" />
        </ProgressTemplate>
      </asp:UpdateProgress>

    Now in the OnClick event I sometimes want to update the content of the update panel, but sometimes I want to change to the next view (this page is part of a multiview control).
    The current behavior is that when I click the button and I update the panel it works great. But when I want to move to the next view nothing happens even though I can see the code to change view is executed. If I then click the button a second time it will change the view. No javascript errors and using the 1.0 version.

    Am I doing something wrong here? Would really appreciate any help!


    /Chris 

     

    /Chris - www.hvaerstillingen.no
    Filed under:
  • Re: Problems with changing views using UpdatePanel inside Multiview

    02-28-2007, 5:23 PM
    • Member
      379 point Member
    • Lovely
    • Member since 10-24-2006, 7:34 PM
    • Posts 104

    Hi, You can use a separate button to update and on to change the View of use DropDownList.

    this ex may be help you.

    <asp:UpdatePanel ID="pnlMeldinger" runat="server" UpdateMode="Conditional">
      <ContentTemplate>
     <asp:DropDownList ID="DropDownList1" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged"
                    runat="server" AutoPostBack="True">
                    <asp:ListItem Value="0">View 1</asp:ListItem>
                    <asp:ListItem Value="1">View 2</asp:ListItem>
                  
                </asp:DropDownList><br />
                <hr />
                <asp:MultiView ID="MultiView1" runat="server" ActiveViewIndex="0">
                    <asp:View ID="View1" runat="server">
                        Now showing View 1<br />
                        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox><strong> </strong>
                        <asp:Button ID="Button1" runat="server" Text="Button" /></asp:View>
                    <asp:View ID="View2" runat="server">
                        Now showing View 2<br />
                        </asp:View>
                    
                </asp:MultiView>
      </ContentTemplate>
      <Triggers>
        <asp:AsyncPostBackTrigger ControlID="btnOK" />
      </Triggers>
    </asp:UpdatePanel>
    
    <asp:Button ID="btnOK" runat="server" Text="Send" OnClick="btnOK_Click" />
      <asp:UpdateProgress ID="progress" runat="server">
        <ProgressTemplate>
          <asp:Label ID="lblProgress" runat="server" Text="BUSY" />
        </ProgressTemplate>
      </asp:UpdateProgress>
     
     
     Protected Sub DropDownList1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs)
            MultiView1.ActiveViewIndex = DropDownList1.SelectedValue
        End Sub
    
     
     Hopes that help.
  • Re: Problems with changing views using UpdatePanel inside Multiview

    02-28-2007, 5:33 PM
    • Member
      17 point Member
    • cnordvik
    • Member since 09-28-2006, 7:17 PM
    • Posts 13

    Hi!

    Problem is that the button validates the form. If the form doesn't validate properly then I want to update the updatepanel. If the form validates, then I want to change the view. So I need the button to be able to update the updatepanel OR change the viewindex. Any reason why the button shouldn't be able to change the viewindex?

     

    /Chris 

    /Chris - www.hvaerstillingen.no
  • Re: Problems with changing views using UpdatePanel inside Multiview

    02-28-2007, 5:45 PM
    • Member
      379 point Member
    • Lovely
    • Member since 10-24-2006, 7:34 PM
    • Posts 104
    cnordvik:

    Hi!

    Problem is that the button validates the form. If the form doesn't validate properly then I want to update the updatepanel. If the form validates, then I want to change the view. So I need the button to be able to update the updatepanel OR change the viewindex. Any reason why the button shouldn't be able to change the viewindex?

     

    /Chris 

     

    Hi, ok no problem to use a button to change the viewindex,

    but my questin here is ,what do you mean of "validates the form"? what is the cases of the form be validated or not? can you give us an example of your code?

     

  • Re: Problems with changing views using UpdatePanel inside Multiview

    02-28-2007, 6:04 PM
    • Member
      17 point Member
    • cnordvik
    • Member since 09-28-2006, 7:17 PM
    • Posts 13

    I'll make a sample app tomorrow, but basically what I am doing is something like this:

    ... OnClick(...)
    {
      if(myWebService.HasErrors(formdata))
       myBtn.Visible = true;
      else
      {
        myBtn.visible = false;
        multiview.ActiveIndex++;
      }
    }

    So when I click the button the following happens:

    I check a Webservice to see if the users has any error in the form data
    ->if errors then I show a error message explaining what fields must be corrected
    ->no error then I move to the next view

    Works great without updatepanels, but then I use updatepanels then the viewindex isn't changed. But it changes if I click the button twice.

    If this doesn't make any sense then I'll make a small sample app and see if I can reproduce the behavior.
     

    <asp:MultiView ID="MultiView1" runat="server" ActiveViewIndex="0">
    <asp:View ID="View1" runat="server">
    ...
    </asp:view>
    <asp:View ID="View2" runat="server">
    <asp:UpdatePanel ID="pnlMeldinger" runat="server" UpdateMode="Conditional">

      <ContentTemplate>
    <asp:label id="mybtn" runat="server" visible="false" text="Please correct input">
      </ContentTemplate>
      <Triggers>
        <asp:AsyncPostBackTrigger ControlID="btnOK" />
      </Triggers>
    </asp:UpdatePanel>

    <asp:Button ID="btnOK" runat="server" Text="Send" OnClick="btnOK_Click" />
      <asp:UpdateProgress ID="progress" runat="server">
        <ProgressTemplate>
          <asp:Label ID="lblProgress" runat="server" Text="BUSY" />
        </ProgressTemplate>
      </asp:UpdateProgress>

    </asp:view> 

    <asp:View ID="lastView" runat="server">
    </asp:view>

     </asp:MultiView>

    /Chris - www.hvaerstillingen.no
  • Re: Problems with changing views using UpdatePanel inside Multiview

    02-28-2007, 6:18 PM
    • Member
      379 point Member
    • Lovely
    • Member since 10-24-2006, 7:34 PM
    • Posts 104

    Hi, you can use this code in the button:

    Page.Validate()
    If Page.IsValid Then
       MultiView1.ActiveViewIndex = MultiView1.ActiveViewIndex + 1
    End If

     

    Hopes that help.

  • Re: Problems with changing views using UpdatePanel inside Multiview

    03-01-2007, 4:01 AM
    • Member
      17 point Member
    • cnordvik
    • Member since 09-28-2006, 7:17 PM
    • Posts 13

    Hi!

    Here is my complete code. Moving to the next view takes two clicks on Button2. I am not using updatepanels when moving to the next view since I have some controls that doesn't support them.

    <asp:MultiView ID="mv" runat="server" ActiveViewIndex="0">
          <asp:View ID="view1" runat="server">
            <asp:UpdatePanel ID="UpdatePanel2" runat="server">
              <ContentTemplate>
                <asp:Label ID="da" runat="server" Text="View1"></asp:Label>
                <asp:Label ID="Label6" runat="server" Text="View1Skjult" Visible="false"></asp:Label>
              </ContentTemplate>
              <Triggers>
                <asp:AsyncPostBackTrigger ControlID="Button2" />
                <asp:AsyncPostBackTrigger ControlID="Button3" />
              </Triggers>
            </asp:UpdatePanel>
            <asp:Button ID="Button2" runat="server" Text="Next view" OnClick="Button2_Click" />
            <asp:Button ID="Button3" runat="server" Text="Show label" OnClick="Button3_Click" />
          </asp:View>
          <asp:View ID="view2" runat="server">
            <asp:Label ID="Label5" runat="server" Text="View2"></asp:Label>
          </asp:View>
        </asp:MultiView>
        <asp:UpdateProgress ID="prog" runat="server">
          <ProgressTemplate>
            Running ajax</ProgressTemplate>
        </asp:UpdateProgress>
     

     

    protected void Button2_Click(object sender, EventArgs e)
        {
            mv.ActiveViewIndex = 1;
        }
        protected void Button3_Click(object sender, EventArgs e)
        {        
            Label6.Visible = true;
        }
     
    /Chris - www.hvaerstillingen.no
  • Re: Problems with changing views using UpdatePanel inside Multiview

    03-01-2007, 4:10 AM
    • Contributor
      2,460 point Contributor
    • Steve Marx
    • Member since 05-26-2006, 8:35 PM
    • Microsoft
    • Posts 643

    Well, during an async postback, you can only update UI that's within the UpdatePanel.  Since the MultiView isn't inside the UpdatePanel, you can't change it.

    What confuses me is that the second click does actually work... my guess is that the second click is doing a full postback, because the first click effectively got rid of the UpdatePanel.  Is that right?  (Is the second click causing a full postback?)

     

    In either case, the MultiView will really need to be inside the UpdatePanel to get this to work.

    Steve Marx | ASP.NET AJAX Evangelist | Microsoft Corporation
  • Re: Problems with changing views using UpdatePanel inside Multiview

    03-01-2007, 4:29 AM
    • Member
      17 point Member
    • cnordvik
    • Member since 09-28-2006, 7:17 PM
    • Posts 13

    Yes the second click is doing a postback. Hmm. Guess I have to rewrite this then. Thanks for the help!

    -Christer 

    /Chris - www.hvaerstillingen.no
  • Re: Problems with changing views using UpdatePanel inside Multiview

    11-06-2007, 10:32 PM
    • Member
      42 point Member
    • cgmenon
    • Member since 12-10-2006, 2:33 PM
    • Posts 59
    I am also having a similar issue with changing views using updatepanel inside multiview. Please suggest how to solve this problem
  • Re: Problems with changing views using UpdatePanel inside Multiview

    07-01-2008, 2:03 PM
    • Member
      8 point Member
    • thduttonuk
    • Member since 10-29-2007, 6:20 AM
    • Conwy, Wales
    • Posts 6

    Hi to solve this.

    1.  Set the update panel to conditional
    2.  Add a onprerender event to the update panel and do the update for the multi view there
    3.  Set the multiview control in the update panel to EnableViewState="False"

     

    Tom Dutton
Page 1 of 1 (11 items)