update panel won't update after submitting a form

Last post 07-12-2009 6:31 PM by aibip. 4 replies.

Sort Posts:

  • update panel won't update after submitting a form

    07-08-2009, 2:47 PM
    • Member
      7 point Member
    • aibip
    • Member since 05-05-2009, 1:38 PM
    • Posts 58

    Update panel won't update after submitting a form.

    I added the submit form button (ID="Insertbtn") as AsyncPostBackTrigger, but no luck.

    I also tried adding UpdatePanel1.Update() and set the UpdatePanel updatemode to Conditional, but it does't refresh.

    The update panel only refreshes when I refresh the page.

    Any idea?


    Thank you



    ------------------------Aspx----------------------


        <form id="form1" runat="server">
            <div id="content" runat="server" width="750px">
                <br />
                <table>
                    <tr>
                        <td>
                            Comment:
                        </td>
                        <td colspan="2">
                            <asp:TextBox ID="addCommenttb" runat="server" Rows="6" TextMode="MultiLine" Width="600" />
                        </td>
                    </tr>
                    <tr>
                        <td>
                            Image:
                        </td>
                        <td colspan="2">
                            <asp:FileUpload ID="FileField" runat="server" size="80" />
                        </td>
                    </tr>
                    <tr>
                        <td>
                            Poster:
                        </td>
                        <td>
                            <asp:DropDownList ID="UserList" runat="server" viewstate="true" DataTextField="UserName"
                                DataValueField="UserName">
                            </asp:DropDownList>
                        </td>
                        <td>
                            <asp:ImageButton ID="Insertbtn" runat="server" ImageUrl="~/Images/btns/btn_submit.jpg" />
                            <asp:HiddenField ID="CustomerIDhf" runat="server" />
                        </td>
                    </tr>
                    <tr>
                        <td>
                        </td>
                        <td colspan="2">
                            <span id="Span1" style="color: red" runat="server"></span>
                        </td>
                    </tr>
                </table>
                <hr />
                <asp:UpdatePanel ID="UpdatePanel1" runat="server">
                    <ContentTemplate>
                        <table>
                            <tr>
                                <td>
                                    <asp:Label ID="ResultsLabel" runat="server" AssociatedControlID="ResultsList" Text="Results per page:" />
                                </td>
                                <td>
                                    <asp:DropDownList runat="server" ID="ResultsList" OnSelectedIndexChanged="ResultsList_SelectedIndexChanged"
                                        EnableViewState="true" AutoPostBack="true">
                                        <asp:ListItem Value="10" />
                                        <asp:ListItem Value="20" Selected="True" />
                                        <asp:ListItem Value="30" />
                                        <asp:ListItem Value="50" />
                                    </asp:DropDownList>
                                    &nbsp;&nbsp;
                                </td>
                                <td>
                                    <asp:DataPager ID="DataPager1" runat="server" PagedControlID="ListView1" PageSize="20">
                                        <Fields>
                                            <asp:TemplatePagerField>
                                                <PagerTemplate>
                                                    Page
                                                    <asp:Label runat="server" ID="CurrentPageLabel" Text="<%# IIf(Container.TotalRowCount>0,  (Container.StartRowIndex / Container.PageSize) + 1 , 0) %>" />
                                                    of
                                                    <asp:Label runat="server" ID="TotalPagesLabel" Text="<%# Math.Ceiling (System.Convert.ToDouble(Container.TotalRowCount) / Container.PageSize) %>" />
                                                    (
                                                    <asp:Label runat="server" ID="TotalItemsLabel" Text="<%# Container.TotalRowCount%>" />
                                                    records)&nbsp;&nbsp;
                                                </PagerTemplate>
                                            </asp:TemplatePagerField>
                                            <asp:NextPreviousPagerField ButtonCssClass="fineprint" ShowFirstPageButton="True"
                                                ShowNextPageButton="False" ShowPreviousPageButton="False" FirstPageText="&lt;"
                                                LastPageText="&gt;" NextPageText="&gt;" PreviousPageText="&lt;" />
                                            <asp:NumericPagerField CurrentPageLabelCssClass="fineprint2" NextPreviousButtonCssClass="fineprint"
                                                NumericButtonCssClass="fineprint" ButtonCount="10" />
                                            <asp:NextPreviousPagerField ButtonCssClass="fineprint" ShowLastPageButton="True"
                                                ShowNextPageButton="False" ShowPreviousPageButton="False" FirstPageText="&lt;"
                                                LastPageText="&gt;" NextPageText="&gt;" PreviousPageText="&lt;" />
                                        </Fields>
                                    </asp:DataPager>
                                </td>
                            </tr>
                        </table>
                        <asp:ListView ID="ListView1" runat="server" DataSourceID="SqlDataSource1" DataKeyNames="BlogID"
                            OnItemCommand="ItemCommand">
                            <LayoutTemplate>
                                <table width="740">
                                    <asp:PlaceHolder ID="itemPlaceholder" runat="server"></asp:PlaceHolder>
                                </table>
                            </LayoutTemplate>
                            <ItemTemplate>
                                <tr>
                                    <td>
                                        <asp:Image ID="Image1" runat="server" ImageUrl='<%#Eval("ImageID","~/blog/images/{0}")%>'
                                            Visible='<%# Convert.ToString(Eval("ImageID"))<>String.Empty %>' /><br />
                                        <%#Eval("Comment")%>
                                    </td>
                                </tr>
                                <tr>
                                    <td align="right">
                                        post#
                                        <asp:Label ID="Label1" runat="server" Text="" />&nbsp;
                                        <%#Eval("PostDate")%>
                                        &nbsp; &nbsp; BY:
                                        <%#Eval("Poster")%>
                                        <br />
                                        <asp:LinkButton ID="editbtn" runat="server" CommandName="Edit">Edit</asp:LinkButton>
                                        <hr />
                                        &nbsp;
                                    </td>
                                </tr>
                            </ItemTemplate>
                        </asp:ListView>
                        </div>
                    </ContentTemplate>
                    <Triggers>
                        <asp:AsyncPostBackTrigger ControlID="DataPager1" />
                    </Triggers>
                </asp:UpdatePanel>
          
        </form>


    -------------------------VB.code behide--------------

     Protected Sub Insertbtn_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles Insertbtn.Click
            If addCommenttb.Text.Trim <> "" Then
                Dim connectionString As String = ConfigurationManager.ConnectionStrings("EmpCustomData").ConnectionString
                Using cn As New System.Data.SqlClient.SqlConnection(connectionString)
                    cn.Open()

                    Using cmd As New System.Data.SqlClient.SqlCommand()
                        With cmd
                            .Connection = cn
                            .CommandType = System.Data.CommandType.Text
                            .CommandText = String.Format("INSERT INTO blog (comment, poster, CustomerID, PostDate) VALUES ('{0}', '{1}', '{2}', '{3}')", addCommenttb.Text, UserList.SelectedValue, CustomerIDhf.Value, DateTime.Now)
                            .ExecuteNonQuery()
                        End With

                    End Using
                End Using
                Span1.InnerHtml = "Post Success!"
                'UpdatePanel1.Update()
                addCommenttb.Text = ""
            End If
        End Sub




        <form id="form1" runat="server">
            <div id="content" runat="server" width="750px">
                <br />
                <table>
                    <tr>
                        <td>
                            Comment:
                        </td>
                        <td colspan="2">
                            <asp:TextBox ID="addCommenttb" runat="server" Rows="6" TextMode="MultiLine" Width="600" />
                        </td>
                    </tr>
                    <tr>
                        <td>
                            Image:
                        </td>
                        <td colspan="2">
                            <asp:FileUpload ID="FileField" runat="server" size="80" />
                        </td>
                    </tr>
                    <tr>
                        <td>
                            Poster:
                        </td>
                        <td>
                            <asp:DropDownList ID="UserList" runat="server" viewstate="true" DataTextField="UserName"
                                DataValueField="UserName">
                            </asp:DropDownList>
                        </td>
                        <td>
                            <asp:ImageButton ID="Insertbtn" runat="server" ImageUrl="~/Images/btns/btn_submit.jpg" />
                            <asp:HiddenField ID="CustomerIDhf" runat="server" />
                        </td>
                    </tr>
                    <tr>
                        <td>
                        </td>
                        <td colspan="2">
                            <span id="Span1" style="color: red" runat="server"></span>
                        </td>
                    </tr>
                </table>
                <hr />
                <asp:UpdatePanel ID="UpdatePanel1" runat="server">
                    <ContentTemplate>
                        <table>
                            <tr>
                                <td>
                                    <asp:Label ID="ResultsLabel" runat="server" AssociatedControlID="ResultsList" Text="Results per page:" />
                                </td>
                                <td>
                                    <asp:DropDownList runat="server" ID="ResultsList" OnSelectedIndexChanged="ResultsList_SelectedIndexChanged"
                                        EnableViewState="true" AutoPostBack="true">
                                        <asp:ListItem Value="10" />
                                        <asp:ListItem Value="20" Selected="True" />
                                        <asp:ListItem Value="30" />
                                        <asp:ListItem Value="50" />
                                    </asp:DropDownList>
                                    &nbsp;&nbsp;
                                </td>
                                <td>
                                    <asp:DataPager ID="DataPager1" runat="server" PagedControlID="ListView1" PageSize="20">
                                        <Fields>
                                            <asp:TemplatePagerField>
                                                <PagerTemplate>
                                                    Page
                                                    <asp:Label runat="server" ID="CurrentPageLabel" Text="<%# IIf(Container.TotalRowCount>0,  (Container.StartRowIndex / Container.PageSize) + 1 , 0) %>" />
                                                    of
                                                    <asp:Label runat="server" ID="TotalPagesLabel" Text="<%# Math.Ceiling (System.Convert.ToDouble(Container.TotalRowCount) / Container.PageSize) %>" />
                                                    (
                                                    <asp:Label runat="server" ID="TotalItemsLabel" Text="<%# Container.TotalRowCount%>" />
                                                    records)&nbsp;&nbsp;
                                                </PagerTemplate>
                                            </asp:TemplatePagerField>
                                            <asp:NextPreviousPagerField ButtonCssClass="fineprint" ShowFirstPageButton="True"
                                                ShowNextPageButton="False" ShowPreviousPageButton="False" FirstPageText="&lt;"
                                                LastPageText="&gt;" NextPageText="&gt;" PreviousPageText="&lt;" />
                                            <asp:NumericPagerField CurrentPageLabelCssClass="fineprint2" NextPreviousButtonCssClass="fineprint"
                                                NumericButtonCssClass="fineprint" ButtonCount="10" />
                                            <asp:NextPreviousPagerField ButtonCssClass="fineprint" ShowLastPageButton="True"
                                                ShowNextPageButton="False" ShowPreviousPageButton="False" FirstPageText="&lt;"
                                                LastPageText="&gt;" NextPageText="&gt;" PreviousPageText="&lt;" />
                                        </Fields>
                                    </asp:DataPager>
                                </td>
                            </tr>
                        </table>
                        <asp:ListView ID="ListView1" runat="server" DataSourceID="SqlDataSource1" DataKeyNames="BlogID"
                            OnItemCommand="ItemCommand">
                            <LayoutTemplate>
                                <table width="740">
                                    <asp:PlaceHolder ID="itemPlaceholder" runat="server"></asp:PlaceHolder>
                                </table>
                            </LayoutTemplate>
                            <ItemTemplate>
                                <tr>
                                    <td>
                                        <asp:Image ID="Image1" runat="server" ImageUrl='<%#Eval("ImageID","~/blog/images/{0}")%>'
                                            Visible='<%# Convert.ToString(Eval("ImageID"))<>String.Empty %>' /><br />
                                        <%#Eval("Comment")%>
                                    </td>
                                </tr>
                                <tr>
                                    <td class="fineprint" align="right">
                                        post#
                                        <asp:Label ID="Label1" runat="server" Text="" />&nbsp;
                                        <%#Eval("PostDate")%>
                                        &nbsp; &nbsp; BY:
                                        <%#Eval("Poster")%>
                                        <br />
                                        <asp:LinkButton ID="editbtn" runat="server" CommandName="Edit">Edit</asp:LinkButton>
                                        <hr />
                                        &nbsp;
                                    </td>
                                </tr>
                            </ItemTemplate>
                        </asp:ListView>
                        </div>
                    </ContentTemplate>
                    <Triggers>
                        <asp:AsyncPostBackTrigger ControlID="DataPager1" />
                    </Triggers>
                </asp:UpdatePanel>
          
        </form>

  • Re: update panel won't update after submitting a form

    07-08-2009, 4:25 PM
    • Member
      290 point Member
    • d.jaspreet
    • Member since 11-21-2008, 6:38 PM
    • Posts 60

     I think if behaving like tah because your UpdatePanel Update trigger is DataPager1

    <Triggers>
                        <asp:AsyncPostBackTrigger ControlID="DataPager1" />
    </Triggers>

    Either add another trigger for your image button

    OR

    Replace Image button with regular submit button <Asp:button>

    Thanks

    JD

     

  • Re: update panel won't update after submitting a form

    07-08-2009, 5:24 PM
    • Member
      7 point Member
    • aibip
    • Member since 05-05-2009, 1:38 PM
    • Posts 58

    Yes, I had two triggers as follow. And it didn't work.

    <Triggers>
                        <asp:AsyncPostBackTrigger ControlID="DataPager1" />

                         <asp:AsyncPostBackTrigger ControlID="Insertbtn" EventName="Click" />
    </Triggers>

    I tried changing btn like you suggested, but no luck.

    It seems it's nothing to do with update panel, and post back is causeing this problems.

    If I remove update panel, contents inside Listview acts same as with update panel.

    I have to mess with data pager or go to different page and come back in order to update contents inside listview.


    Thank you


  • Re: update panel won't update after submitting a form

    07-08-2009, 11:11 PM

    How UpdatePanel Controls Are Refreshed

    The following list describes the property settings of the UpdatePanel control that determine when a panel's content is updated during partial-page rendering.

    • If the UpdateMode property is set to Always, the UpdatePanel control’s content is updated on every postback that originates from anywhere on the page. This includes asynchronous postbacks from controls that are inside other UpdatePanel controls, and postbacks from controls that are not inside UpdatePanel controls.

    • If the UpdateMode property is set to Conditional, the UpdatePanel control’s content is updated when one of the following is true:

      • When the postback is caused by a trigger for that UpdatePanel control.

      • When you explicitly call the UpdatePanel control's Update() method.

      • When the UpdatePanel control is nested inside another UpdatePanel control and the parent panel is updated.

      • When the ChildrenAsTriggers property is set to true and any child control of the UpdatePanel control causes a postback. Child controls of nested UpdatePanel controls do not cause an update to the outer UpdatePanel control unless they are explicitly defined as triggers for the parent panel.

    If the ChildrenAsTriggers property is set to false and the UpdateMode property is set to Always, an exception is thrown. The ChildrenAsTriggers property is intended to be used only when the UpdateMode property is set to Conditional.

    Chetan Sarode
    Software Engineer,
    Approva Systems Pvt Ltd,
    Pune, India.
  • Re: update panel won't update after submitting a form

    07-12-2009, 6:31 PM
    Answer
    • Member
      7 point Member
    • aibip
    • Member since 05-05-2009, 1:38 PM
    • Posts 58

    I found what was causing this.

    It was because the listview needed to rebind the data.

Page 1 of 1 (5 items)