Click here to Skip to main content
15,892,005 members

Javascript function not called from Datagrid Onpageindexchanged event

Revision 1
XML
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">

       <b> window.onunload = unloadPage;  </b>

        var isClose = false;

 function somefunction()
        {
        isClose = false;
        }
       <b> function unloadPage()
        {
        if(!isClose)
        {
            document.getElementById('btnimglogout').click();
        }
        } </b>
       <b> function setUser()
        {
            isClose = true;
        }</b>&lt;/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
           <b> If (Not ClientScript.IsStartupScriptRegistered("alert")) Then
                Page.ClientScript.RegisterStartupScript(Me.GetType(), "alert", "setUser();", True)
            End If</b>            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.
Posted 8-Nov-12 1:52am by swatiiiiiiiiii.
Tags: