简体   繁体   中英

Button Postback Not Firing in asp.net

I have a button in an update panel. When I click on the button it doesn't hit the server side click method. Not sure what is going on. Below is the code for you folks. Any insights on what could be happening would greatly helpful. The ID of the button is btnPost. It is a part of the update panel below.

<asp:UpdatePanel ID="atlaspnlpost" runat="server" UpdateMode="Conditional">
            <ContentTemplate>
                <asp:Panel ID="pnlPost" runat="server" Style="width: 855px" GroupingText="Accounting use only">
                    <table class="MainSectionBody" style="width: 855px">
                        <tr style="height: 30px">
                            <td style="width: 165px">
                                <asp:Label ID="Label4" runat="server" Text="Accounting Date" Width="160px"></asp:Label>
                            </td>
                            <td style="width: 200px">
                                <asp:TextBox ID="txtAcctDate" runat="server" Width="200px" TabIndex="13" Text="01/18/2018"></asp:TextBox>&nbsp;
                            </td>
                            <td style="width: 85px">
                                <a runat="server" id="lnkAcctDate" style="cursor: hand">
                                    <asp:Image ID="Image2" runat="server" ImageUrl="~/Images/calendar_small.gif" TabIndex="98">
                                    </asp:Image></a>
                                <asp:CompareValidator ID="cvAccDate" runat="server" ErrorMessage="Accounting Date is Required"
                                    Operator="DataTypeCheck" SetFocusOnError="True" Type="Date" ControlToValidate="txtAcctDate">*</asp:CompareValidator>
                            </td>
                            <td style="width: 405px">
                                <asp:CheckBox ID="chkApprove" Text="Approved By Accounting" runat="server" TabIndex="14" />
                            </td>
                        </tr>
                        <tr style="height: 30px">
                            <td style="width: 165px">
                                <asp:Label ID="lblApprover" runat="server" Text="Approver Name" Width="160px"></asp:Label>
                            </td>
                            <td style="width: 200px">
                                <asp:TextBox ID="txtApprover" runat="server" Width="200px" SkinID="ReadOnlyTextBox"
                                    ReadOnly="True" TabIndex="99"></asp:TextBox>
                            </td>
                            <td style="width: 85px">
                                <td style="width: 405px">
                                    <%--<asp:Button ID="btnPost" runat="server" Text="Post" Width="76px" TabIndex="15" />--%>
                                </td>
                        </tr>
                         <tr style="height: 30px">
                            <td style="width: 165px">
                                <asp:Label ID="lblDescription" runat="server" Text="Description" Width="160px"></asp:Label>
                            </td>
                            <td style="width: 200px">
                                <asp:TextBox ID="txtdescription" runat="server" Width="200px"  TabIndex="99" 
                                    TextMode="MultiLine"></asp:TextBox>
                            </td>
                            <td style="width: 85px">
                                <td style="width: 405px">
                                  <%-- <asp:Button ID="btnPost" runat="server" Text="Post" Width="76px" TabIndex="15" />--%>
                                </td>
                        </tr>
                        <tr style="height: 30px">
                            <td style="width: 165px">
                                <asp:Label ID="lblFinanceexplanation" runat="server" Text="FinanceExpalnation" Width="160px"></asp:Label>
                            </td>
                            <td style="width: 200px">
                                <asp:TextBox ID="txtFinanceExplanation" runat="server" Width="200px"  TabIndex="99" 
                                    TextMode="MultiLine"></asp:TextBox>
                            </td>
                            <td style="width: 85px">
                                <td style="width: 405px">
                                   <asp:Button ID="btnPost" runat="server" Text="Post" Width="76px" TabIndex="15" />
                                </td>
                        </tr>
                    </table>
                </asp:Panel>
            </ContentTemplate>
            <Triggers>
                <asp:AsyncPostBackTrigger ControlID="btnSearch" EventName="Click" />
                <asp:AsyncPostBackTrigger ControlID="btnRefresh" EventName="Click" />
                 <asp:AsyncPostBackTrigger ControlID="ddlYear" EventName="SelectedIndexChanged" />

            </Triggers>
        </asp:UpdatePanel>

Below is the Button Post Back Event:-

Protected Sub btnPost_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnPost.Click
            Dim sErrMsg As String = String.Empty
            If CStr(Session(Common.Session.UserName)) = String.Empty Then
                Response.Redirect("~/ErrorInfo.aspx?mes=Your session has expired. Please search the deal again", False)
            Else
                If Not ValidatePost(sErrMsg) Then
                    Me.DispMessage(sErrMsg)
                Else
                    Try
                        If ValidateandSaveGrid() = True Then
                            SaveHoldBackAloc()
                            SaveEmpAlloc()
                            SavePaymentLog()
                            ConfigureAfterPost()
                            getHoldbackHistory()
                        Else
                            Me.DispMessage("Invalid Data")
                        End If

                    Catch ex As Exception
                    End Try
                End If
            End If
        End Sub

you seen to add one more attribute to your button

OnClick="btnPost_Click"

It should look like this:

<asp:Button ID="btnPost" runat="server" Text="Post" OnClick="btnPost_Click" Width="76px" TabIndex="15" />

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM