Click here to Skip to main content

swatiiiiiiiiii asked:

Open original thread
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" />
                                                    &lt;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" />
                                                    &lt;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.
Tags: VB.NET

Preview



When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the The Code Project Open License (CPOL).



Advertise | Privacy | Mobile
Web04 | 2.8.141216.1 | Last Updated 26 Mar 2009
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100