locked
update panel issue RRS feed

  • Question

  • User582566331 posted

     I converted the application from .net 3.5 to 4.6. I added dropdownlist in update panel .But the whole page is refreshing. The same code is working fine with asp.net 3.5.My code is as below

    whenever I change item in dropdownlist(test) its causing full page post back instead of partial postback.

    <asp:ScriptManager runat="server" >

    </asp:ScriptManager>
    <div>
    <asp:UpdatePanel runat="server" UpdateMode="Conditional">
    <ContentTemplate>
    <asp:DropDownList ID="test" runat="server" AutoPostBack="true">

    </asp:DropDownList>

    <%-- <asp:UpdatePanel ID="UpState" runat="server">
    <ContentTemplate>--%>
    <asp:DropDownList ID="ddlState" runat="server" class="form-control"
    Visible="False" AutoPostBack="True">
    </asp:DropDownList>
    <asp:TextBox ID="txtState" runat="server" MaxLength="50"></asp:TextBox>
    <asp:RequiredFieldValidator ID="rfvddlState" runat="server"
    ErrorMessage="State Required!" InitialValue="" ControlToValidate="DdlState"
    SetFocusOnError="True" Display="Dynamic" class="star"></asp:RequiredFieldValidator>
    <asp:RequiredFieldValidator ID="rfvtxtState" runat="server"
    ErrorMessage="State Required!" ControlToValidate="txtState"
    SetFocusOnError="True" Display="Dynamic" class="star"></asp:RequiredFieldValidator>
    </ContentTemplate>
    </asp:UpdatePanel>

    If Not IsPostBack Then
    selectCountryState("Country", "CountryId", "CountryName", test, "--Select Country--") 'Calling the Method for filling dropdowncountry
    End If
    End Sub

    Protected Sub test_SelectedIndexChanged(sender As Object, e As EventArgs) Handles test.SelectedIndexChanged
    If test.SelectedValue = _CountryId Then
    selectCountryState("StateMaster", "Code", "State", ddlState, "--Select State--") 'Calling the Method for filling dropdownState
    ddlState.Visible = True
    txtState.Visible = False
    Else
    txtState.Visible = True
    ddlState.Visible = False
    txtState.Text = ""
    End If
    End Sub

    Monday, October 1, 2018 9:32 AM

Answers

  • User61956409 posted

    Hi sweetyPaul,

    I do a test with your code, it works as expected on my side.

    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
    </head>
    <body>
        <form id="form1" runat="server">
            <div>
                <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
                <div>
                    <%=DateTime.Now %>
                    <br />
                    <br />
                    <h3>Following Content is inside UpdatePanel</h3>
                    <asp:UpdatePanel runat="server" UpdateMode="Conditional">
                        <ContentTemplate>
                            <%=DateTime.Now %>
                            <br />
    
                            <asp:DropDownList ID="test" runat="server" AutoPostBack="true">
                                <asp:ListItem>Item1</asp:ListItem>
                                <asp:ListItem>Item2</asp:ListItem>
                                <asp:ListItem>Item3</asp:ListItem>
                            </asp:DropDownList>
                            <asp:DropDownList ID="ddlState" runat="server" class="form-control"
                                Visible="False" AutoPostBack="True">
                            </asp:DropDownList>
                            <asp:TextBox ID="txtState" runat="server" MaxLength="50"></asp:TextBox>
                            <asp:RequiredFieldValidator ID="rfvddlState" runat="server"
                                ErrorMessage="State Required!" InitialValue="" ControlToValidate="DdlState"
                                SetFocusOnError="True" Display="Dynamic" class="star"></asp:RequiredFieldValidator>
                            <asp:RequiredFieldValidator ID="rfvtxtState" runat="server"
                                ErrorMessage="State Required!" ControlToValidate="txtState"
                                SetFocusOnError="True" Display="Dynamic" class="star"></asp:RequiredFieldValidator>
                        </ContentTemplate>
                    </asp:UpdatePanel>
                </div>
            </div>
        </form>
    </body>
    </html>

    Test Result:

    If possible, you can create a new project with .NET framework 4.6 and test if the above code work fine.

    With Regards, 

    Fei Han

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, October 2, 2018 7:28 AM
  • User-471420332 posted

    Don't copy paste your old code to into new project code, try to write code then check.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, October 3, 2018 5:16 AM

All replies

  • User-943250815 posted

    Try add  Triggers

    <asp:UpdatePanel runat="server" UpdateMode="Conditional">
      <Triggers>
        <asp:AsyncPostBackTrigger ControlID="test" EventName="SelectedIndexChanged" />
      </Triggers>
      <ContentTemplate>
        <asp:DropDownList ID="test" runat="server" AutoPostBack="true"></asp:DropDownList>
        <asp:DropDownList ID="ddlState" runat="server" class="form-control" Visible="False" AutoPostBack="True"></asp:DropDownList>
        <asp:TextBox ID="txtState" runat="server" MaxLength="50"></asp:TextBox>
        <asp:RequiredFieldValidator ID="rfvddlState" runat="server" ErrorMessage="State Required!" InitialValue="" ControlToValidate="DdlState" SetFocusOnError="True" Display="Dynamic" class="star"></asp:RequiredFieldValidator>
        <asp:RequiredFieldValidator ID="rfvtxtState" runat="server" ErrorMessage="State Required!" ControlToValidate="txtState" SetFocusOnError="True" Display="Dynamic" class="star"></asp:RequiredFieldValidator>
      </ContentTemplate>
    </asp:UpdatePanel>

    Monday, October 1, 2018 3:14 PM
  • User61956409 posted

    Hi sweetyPaul,

    I do a test with your code, it works as expected on my side.

    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
    </head>
    <body>
        <form id="form1" runat="server">
            <div>
                <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
                <div>
                    <%=DateTime.Now %>
                    <br />
                    <br />
                    <h3>Following Content is inside UpdatePanel</h3>
                    <asp:UpdatePanel runat="server" UpdateMode="Conditional">
                        <ContentTemplate>
                            <%=DateTime.Now %>
                            <br />
    
                            <asp:DropDownList ID="test" runat="server" AutoPostBack="true">
                                <asp:ListItem>Item1</asp:ListItem>
                                <asp:ListItem>Item2</asp:ListItem>
                                <asp:ListItem>Item3</asp:ListItem>
                            </asp:DropDownList>
                            <asp:DropDownList ID="ddlState" runat="server" class="form-control"
                                Visible="False" AutoPostBack="True">
                            </asp:DropDownList>
                            <asp:TextBox ID="txtState" runat="server" MaxLength="50"></asp:TextBox>
                            <asp:RequiredFieldValidator ID="rfvddlState" runat="server"
                                ErrorMessage="State Required!" InitialValue="" ControlToValidate="DdlState"
                                SetFocusOnError="True" Display="Dynamic" class="star"></asp:RequiredFieldValidator>
                            <asp:RequiredFieldValidator ID="rfvtxtState" runat="server"
                                ErrorMessage="State Required!" ControlToValidate="txtState"
                                SetFocusOnError="True" Display="Dynamic" class="star"></asp:RequiredFieldValidator>
                        </ContentTemplate>
                    </asp:UpdatePanel>
                </div>
            </div>
        </form>
    </body>
    </html>

    Test Result:

    If possible, you can create a new project with .NET framework 4.6 and test if the above code work fine.

    With Regards, 

    Fei Han

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, October 2, 2018 7:28 AM
  • User582566331 posted

    Yes .its working in new project. But not working with converted project. Couldn't resolve the issue.

    Wednesday, October 3, 2018 4:44 AM
  • User-471420332 posted

    Don't copy paste your old code to into new project code, try to write code then check.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, October 3, 2018 5:16 AM
  • User582566331 posted

    Thank you all.Its working fine .....

    Wednesday, October 3, 2018 7:31 AM
  • User-471420332 posted

    which one is the correct answer please mark as answer.

    Wednesday, October 3, 2018 7:55 AM