label in popup isnot appearing as expected RRS feed

  • Question

  • User-1767698477 posted

    I have a popup which appears and allows to edit or add a new row to database. I have a dropdown called ddgiftsource which when the index number 6 is selected (Other Source) they have to complete the textbox Othersource.  So just before completing the code to save the details to the database, I have:

     Protected Sub btn2Insert_Click(ByVal sender As Object, ByVal e As EventArgs)
            If ddgiftsource.SelectedIndex = 6 Then
                If txtothersource.Text = "" Then
                    lblerror.Visible = True
                    Exit Sub
                End If
            End If

    The popup is just closing upon reaching Exit Sub and the message in the label is not appearing or if it is appearing, it is not viewable since the box closes. The message needs to appear and the box should stay open. Why isn't this happening now? Below is the last row of the popup.

                                    <td colspan="4" align="center">
                                        <asp:Label ID="lblerror" runat="server" ForeColor="Red" Text="If you select Other Source, you must<br /> complete the Other Source field" Font-Bold="true" Width="300px"></asp:Label><br />
                                        <asp:HiddenField ID="HiddenField2" runat="server" />
                                        <asp:Button ID="btn2Update" CommandName="Update" runat="server" Text="Update" OnClick="btn2Update_Click" CausesValidation="False" />
                                        <asp:Button ID="btn2Insert" CommandName="Insert" runat="server" Text="Add" OnClick="btn2Insert_Click" CausesValidation="False" />
                                        <asp:Button ID="btn2Cancel" runat="server" Text="Cancel" />

    Monday, May 31, 2021 5:48 PM

All replies

  • User-943250815 posted

    Have in mind all buttons 3 button in your code does a PostBack, so your page is recreated at every click.
    Usually a Popup is hidden on page load then after some action like a button click it is switched to show/pop.

    Monday, May 31, 2021 6:37 PM