0

I have have an asp.net check box with autopostback set to true inside an update panel. When I check the check box it shows the other controls that I want to show. When I un-check the check box a value in the database is updated. This is all working fine.

If I want to move to another page after un-checking the check box a dialog which is asking whether I want to stay on this page or leave the page is displayed. How can I stop that dialog box from appearing?

<asp:UpdatePanel runat="server" ID="upOnProbation" UpdateMode="Conditional">
        <ContentTemplate>
            <div>
                <table>
                    <tr>
                        <td>
                            <asp:CheckBox runat="server" Text="On Probation" ID="chkOnProbation" AutoPostBack="true" ClientIDMode="AutoID" />
                        </td>
                    </tr>
                    <asp:PlaceHolder runat="server" ID="plcProbabtionDates" Visible="false">
                        <tr>
                            <td>
                                Start date
                            </td>
                            <td>
                                <ComponentArt:Calendar runat="server" ID="dtStart" ControlType="Picker" PickerFormat="Short">
                                </ComponentArt:Calendar>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                End date
                            </td>
                            <td>
                                <ComponentArt:Calendar runat="server" ID="dtEnd" ControlType="Picker" PickerFormat="Short">
                                </ComponentArt:Calendar>
                            </td>
                        </tr>
                         <tr>
                        <td>
                            <asp:Button runat="server" ID="btnSave" Text="Save" CssClass="btn" />
                        </td>
                    </tr>
                    </asp:PlaceHolder>                   
                </table>
            </div>
        </ContentTemplate>

    </asp:UpdatePanel>




Protected Sub chkOnProbation_CheckedChanged(sender As Object, e As System.EventArgs) Handles chkOnProbation.CheckedChanged
        If chkOnProbation.Checked Then
            plcProbabtionDates.Visible = True
            dtStart.SelectedDate = DateTime.Now
            dtEnd.SelectedDate = DateTime.Now.AddMonths(6)
        Else
            plcProbabtionDates.Visible = False
            objCompany.On_Probation = False
            objCompany.Save(UserStaffID)
        End If
    End Sub
Pow-Ian
  • 3,607
  • 1
  • 22
  • 31
Joshua
  • 2,275
  • 7
  • 41
  • 57

1 Answers1

0

Check this previous answer for an explanation as to why this happens.

basically when you have a form on a web page the browser will fire an onbeeforeunload event for you to ensure that unsaved changes are accounted for.

The answer to the previous question states that you can avoid this by setting the handler to null

window.onbeforeunload = null;
Community
  • 1
  • 1
Pow-Ian
  • 3,607
  • 1
  • 22
  • 31