Click here to Skip to main content
11,705,763 members (57,329 online)
Rate this: bad
Please Sign up or sign in to vote.
See more: VB.NET
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()
    function setUser()
        isClose = true;
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" />
                                                        <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" />
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
           If (Not ClientScript.IsStartupScriptRegistered("alert")) Then
    Page.ClientScript.RegisterStartupScript(Me.GetType(), "alert", "setUser();", True)
            End If            
            dgttumfileview.CurrentPageIndex = e.NewPageIndex
        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.
Posted 8-Nov-12 1:52am
Edited 8-Nov-12 7:11am
(no name)139.6K
ryanb31 at 8-Nov-12 7:55am
Did you finish the question?
swatiiiiiiiiii at 8-Nov-12 23:21pm
ya.. How can I call the javascript function 'SetUser' from page event of Datagrid in codebehind when window.onunload is used ?? Page gets unloaded before the javascript function gets executed.
ryanb31 at 9-Nov-12 8:02am
Why is the page being unloaded? What are you trying to accomplish with the unload event?
swatiiiiiiiiii at 12-Nov-12 0:20am
I have to implement functionality on page unload to logout the user when he closes the browser
ryanb31 at 12-Nov-12 7:42am
First of all, there is no guaranteed code that will log out a user because there are many ways a browser can close and you won't know about it (machine crashes for example) because the web is a disconnected app. You can try some things listed at but you may want to rethink why you want to know when they are logged out.
Dave Kreskowiak at 8-Nov-12 11:28am
That's not ASP.NET code. THat's not ANY code. YOu may want to look at what you posted and fix your question so people can understand it.
aspnet_regiis -i at 8-Nov-12 12:50pm
Whereeeeeeeeeeeeeee is the code? Working toooooooo late is dangerous for the brain....

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 208
1 Sergey Alexandrovich Kryukov 142
2 Inimicos 60
3 ppolymorphe 57
4 ProgramFOX 50
0 OriginalGriff 9,037
1 Sergey Alexandrovich Kryukov 8,417
2 CPallini 5,189
3 Maciej Los 4,726
4 Mika Wendelius 3,626

Advertise | Privacy | Mobile
Web03 | 2.8.150819.1 | Last Updated 8 Nov 2012
Copyright © CodeProject, 1999-2015
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