Javascript function not called from Datagrid Onpageindexchanged event
Revision 1
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></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
<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.