I have a function in javascript and a Datagrid. I have used an event 'onunload' in javascript. Below is my ASP.NET code.
<script language="javascript" type="text/javascript">
window.onunload = unloadPage;
var isClose = false;
function somefunction()
{
isClose = false;
}
function unloadPage()
{
if(!isClose)
{
document.getElementById('btnimglogout').click();
}
}
function setUser()
{
isClose = true;
}
</script>
And the datagrid is:
<asp:DataGrid ID="<b>dgttumfileview</b>" runat="server" AllowPaging="True" AutoGenerateColumns="False"
BorderColor="Black" CssClass="maintext" ForeColor="Black" HorizontalAlign="Center" CellPadding="1" Font-Bold="False" Font-Italic="False" Font-Overline="False" Font-Strikeout="False" Font-Underline="False" BorderWidth="1px" CellSpacing="1" Width="796px">
<ItemStyle HorizontalAlign="Center" BorderColor="#404040" BorderStyle="Solid" />
<HeaderStyle Font-Bold="True" HorizontalAlign="Center" Font-Italic="False" Font-Overline="False" Font-Strikeout="False" Font-Underline="False" />
<Columns>
<asp:BoundColumn DataField="sr_no" HeaderText="Sr No."></asp:BoundColumn>
<PagerStyle Font-Bold="True" HorizontalAlign="Right" Mode="NumericPages" Font-Italic="False" Font-Overline="False" Font-Strikeout="False" Font-Underline="False" />
<SelectedItemStyle BorderColor="#404040" BorderStyle="Solid" />
</asp:DataGrid>
And the VB.NET code for pageselectedindexchanged event is:
Protected Sub dgttumfileview_PageIndexChanged(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridPageChangedEventArgs) Handles dgttumfileview.PageIndexChanged
Try
If (Not ClientScript.IsStartupScriptRegistered("alert")) Then
Page.ClientScript.RegisterStartupScript(Me.GetType(), "alert", "setUser();", True)
End If
dgttumfileview.CurrentPageIndex = e.NewPageIndex
DataGridBind()
Catch ex As Exception
Trace.Warn("dgUnPaidScroll_PageIndexChanged", ex.Message)
End Try
End Sub
Now the issue is the page event calls the javascript function setUser() only when window.onunload is not used. But if I am using window.onunload function, the Javascript function SetUser is not called.
I have spend my whole day but could not get out of it.