This is a migrated thread and some comments may be shown as answers.

problem with onbeforeunload and radajaxloadingpanel

2 Answers 125 Views
Grid
This is a migrated thread and some comments may be shown as answers.
ADT
Top achievements
Rank 1
ADT asked on 14 Nov 2012, 10:12 PM
Hello,

I have a webpage that has a grid on it, the grid opens in edit mode and functions exactly as needed. I have it so it saves everytime you go to filter, sort rows, change page size, etc...all per user request. The last request was to force a save when they leave the page. I am attempting to do it with
window.onbeforeunload = function (evt) {
$find("<%=RadAjaxManager1.ClientID %>").ajaxRequest();
}

This forces the page to save and works as needed, they do not want confirmation, they want it to save no matter what. My issue is that when I put the above code on the page, the radAjaxLoadingPanel no longer displays on any item command clicks or on paging, sorting. It only shows up on filtering. I have no idea why this may be occuring.
Below I will paste all my code so you can see everything that is occuring. If you have any other thoughts please let me know. If you notice anything else that does not look correct, please let me know. I am new to learning telerik and these pages but am pretty happy with what I have programmed so far and everything aside from the "LoadingPanel" right now works as needed.Thank you in advance.
ASPX code:
<%@ Page Title="" Language="VB" MasterPageFile="~/MasterNoBanner.master" AutoEventWireup="false" CodeFile="AddTonnage.aspx.vb" Inherits="AddTonnage" %>
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
<asp:Content ID="Content1" ContentPlaceHolderID="cphBodyText" Runat="Server">
<div style="width: 980px; clear: both; border-bottom: 0px solid black;" >
<telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">
<script type="text/javascript">
var blnSaveGrid = "True";
function CatchKeyPress(sender, args) {
if (args.get_keyCode() == 13) { //Enter Key
var e = args.get_domEvent().rawEvent;
e.returnValue = false;
e.cancelBubble = true;
if (e.stopPropagation) {
e.preventDefault();
e.stopPropagation();
}
}
if (args.get_keyCode() == 27) { //esca Key
var e = args.get_domEvent().rawEvent;
e.returnValue = false;
e.cancelBubble = true;
if (e.stopPropagation) {
e.preventDefault();
e.stopPropagation();
}
}
}
function setFocus2(down, current, right, evt) {
var keynum;
var event = evt || window.event;
if (window.event) // IE
{
keynum = window.event.keyCode;
}
else if (e.which) // Netscape/Firefox/Opera
{
keynum = window.event.which;
}
if (keynum == 9 || keynum == 13) {
if (event.shiftKey == 1) {
}
else {
var today = new Date();
var dd = today.getDate();
var mm = today.getMonth() + 1; //January is 0!
var yyyy = today.getFullYear();
if (dd < 10) { dd = '0' + dd }
if (mm < 10) { mm = '0' + mm }
var now = mm + '/' + dd + '/' + yyyy;
var txtDown = $get(down);
var txtCurrent = $get(current);
var txtRight = $get(right);
txtRight.value = now;
txtRight.focus();
txtRight.select();
// txtCurrent.focus();
// txtCurrent.select();
txtDown.focus();
txtDown.select();
evt.preventDefault();
}
}
//return false;
}
function lastFocus(right, evt) {
var keynum;
var event = evt || window.event;
if (window.event) // IE
{
keynum = window.event.keyCode;
}
else if (e.which) // Netscape/Firefox/Opera
{
keynum = window.event.which;
}
if (keynum == 9 || keynum == 13) {
if (event.shiftKey == 1) {
}
else {
var today = new Date();
var dd = today.getDate();
var mm = today.getMonth() + 1; //January is 0!
var yyyy = today.getFullYear();
if (dd < 10) { dd = '0' + dd }
if (mm < 10) { mm = '0' + mm }
var now = mm + '/' + dd + '/' + yyyy;
var txtRight = $get(right);
txtRight.value = now;
txtRight.focus();
txtRight.select();
evt.preventDefault();
}
}
}
window.onbeforeunload = function (evt) {
$find("<%=RadAjaxManager1.ClientID %>").ajaxRequest();
}
</script>
</telerik:RadCodeBlock>
<telerik:RadWindowManager runat="server" ID="RadWindowManager1">
</telerik:RadWindowManager>
<telerik:RadFormDecorator ID="RadFormDecorator1" runat="server" DecoratedControls="Default,Select,Textbox"
EnableRoundedCorners="false" />
<telerik:RadAjaxManager ID="RadAjaxManager1" runat="server" OnAjaxRequest="RadAjaxManager1_AjaxRequest">
<AjaxSettings>
<telerik:AjaxSetting AjaxControlID="RadAjaxManager1">
<UpdatedControls>
<telerik:AjaxUpdatedControl ControlID="RadGrid1" LoadingPanelID="RadAjaxLoadingPanel1" />
<telerik:AjaxUpdatedControl ControlID="Label1" />
<telerik:AjaxUpdatedControl ControlID="lblQuarterYear" />
</UpdatedControls>
</telerik:AjaxSetting>
<telerik:AjaxSetting AjaxControlID="RadAjaxManager1" EventName="RadAjaxManager1_AjaxRequest">
<UpdatedControls>
<telerik:AjaxUpdatedControl ControlID="RadGrid1" LoadingPanelID="RadAjaxLoadingPanel1" />
<telerik:AjaxUpdatedControl ControlID="Label1" />
<telerik:AjaxUpdatedControl ControlID="lblQuarterYear" />
</UpdatedControls>
</telerik:AjaxSetting>
<telerik:AjaxSetting AjaxControlID="RadGrid1">
<UpdatedControls>
<telerik:AjaxUpdatedControl ControlID="RadGrid1" LoadingPanelID="RadAjaxLoadingPanel1" />
<telerik:AjaxUpdatedControl ControlID="Label1" />
<telerik:AjaxUpdatedControl ControlID="lblQuarterYear" />
</UpdatedControls>
</telerik:AjaxSetting>
<telerik:AjaxSetting AjaxControlID="btnGrid">
<UpdatedControls>
<telerik:AjaxUpdatedControl ControlID="RadGrid1" LoadingPanelID="RadAjaxLoadingPanel1" />
<telerik:AjaxUpdatedControl ControlID="Label1" />
<telerik:AjaxUpdatedControl ControlID="lblQuarterYear" />
</UpdatedControls>
</telerik:AjaxSetting>
</AjaxSettings>
</telerik:RadAjaxManager>
<telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server" EnableViewState="true" />
<table width="98%" border="0">
<tr valign="top"><td width="35%"><span style="color: Blue; font-weight: bold;">Add Quantity to loads of POs that are not complete and quantity is empty.</span>
<br /><span style="background-color: #33CCCC;">Click on label to re-sort</span></td>
<td valign="middle">Quarter
<telerik:RadNumericTextBox incrementsettings-interceptarrowskeys="false" incrementsettings-interceptmousewheel="false" ID="txtQuarter" runat="server" Width="50px"
MaxValue="4" MinValue="1" >
<NumberFormat ZeroPattern="n" DecimalDigits="0"></NumberFormat>
</telerik:RadNumericTextBox>
Year
<telerik:RadNumericTextBox incrementsettings-interceptarrowskeys="false" incrementsettings-interceptmousewheel="false" ID="txtYear" runat="server" Width="75px"
MaxValue="2050" MinValue="2000" >
<NumberFormat ZeroPattern="n" DecimalDigits="0" GroupSeparator=""></NumberFormat>
</telerik:RadNumericTextBox> <telerik:RadButton runat="server" ID="btnGrid" Text="Enable Grid" ></telerik:RadButton>
<br /><asp:Label id="lblQuarterYear" runat="server" Text="" Visible="false"></asp:Label>
</td></tr>
<tr><td colspan="2" align="center"><asp:Label id="Label1" runat="server" Text="" Visible="true"></asp:Label></td></tr>
</table>
<telerik:RadGrid ID="RadGrid1" DataSourceID="SqlDataSource1"
ShowStatusBar="True"
AllowSorting="True" GridLines="None" runat="server" AllowFilteringByColumn="true"
AutoGenerateColumns="False" CellSpacing="0" AllowAutomaticDeletes="True" AllowMultiRowEdit="true"
AllowPaging="True" PageSize="50" Height="800px" Width="950px" Enabled="false" >
<ClientSettings>
<Scrolling AllowScroll="true" UseStaticHeaders="true"></Scrolling>
</ClientSettings>
<MasterTableView EditMode="InPlace" DataKeyNames="LoadID" DataSourceID="SqlDataSource1" CommandItemDisplay="Top" InsertItemPageIndexAction="ShowItemOnCurrentPage" >
<CommandItemTemplate>
<table width="100%">
<tr>
<td align="right"> <asp:LinkButton ID="btnCancelChanges" runat="server" CommandName="CancelChanges" Visible="true"><img style="border:0px" alt="" src="Images/Cancel.gif" />- Clear all Changes </asp:LinkButton>
<asp:LinkButton ID="btnSaveChanges" runat="server" CommandName="SaveChanges" Visible="true"><img style="border:0px" alt="" src="Images/Update.gif" />- Save All changes</asp:LinkButton>
</td>
</tr>
</table>
</CommandItemTemplate>
<CommandItemSettings ExportToPdfText="Export to PDF"></CommandItemSettings>
<RowIndicatorColumn Visible="True" FilterControlAltText="Filter RowIndicator column"></RowIndicatorColumn>
<ExpandCollapseColumn Visible="True" FilterControlAltText="Filter ExpandColumn column"></ExpandCollapseColumn>
<Columns>
<telerik:GridButtonColumn DataTextFormatString="Copy {0}"
ButtonType="ImageButton" UniqueName="CopyRow" HeaderText="Copy"
ItemStyle-HorizontalAlign="Center" HeaderStyle-HorizontalAlign="Center" CommandName="CopyPaste"
DataTextField="LoadID" ImageUrl="../images/ClientEditBatchUpdates/Img/Copy.gif" ShowInEditForm="true">
</telerik:GridButtonColumn>
<%-- <telerik:GridButtonColumn ShowInEditForm="true" ButtonType="ImageButton" HeaderText="Copy" Text="Copy Row '{0}'" CommandName="CopyPaste({0})" UniqueName="CopyRow" ImageUrl="../images/ClientEditBatchUpdates/Img/Copy.gif" DataTextField="LoadID">
<HeaderStyle Width="45px" />
<ItemStyle Width="45px" />
</telerik:GridButtonColumn>--%>
<telerik:GridBoundColumn DataField="LoadID" DataType="System.Int32" HeaderText="LoadID"
SortExpression="LoadID" UniqueName="LoadID" ReadOnly="true" Visible="false">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="SupplierName" DataType="" HeaderText="Supplier Name"
SortExpression="SupplierName" UniqueName="SupplierName" ReadOnly="true" Visible="true" AllowFiltering="true" FilterDelay="1000" CurrentFilterFunction="Contains" ShowFilterIcon="false" FilterControlWidth="95%">
<HeaderStyle Width="150px"></HeaderStyle>
<ItemStyle Width="150px"></ItemStyle>
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="CompanyName" DataType="" HeaderText="Member"
SortExpression="CompanyName" UniqueName="CompanyName" ReadOnly="true" Visible="true" AllowFiltering="true" FilterDelay="1000" CurrentFilterFunction="Contains" ShowFilterIcon="false" FilterControlWidth="95%" >
<HeaderStyle Width="150px"></HeaderStyle>
<ItemStyle Width="150px"></ItemStyle>
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="PONumber" DataType="" HeaderText="PO Number"
SortExpression="PONumber" UniqueName="PONumber" ReadOnly="true" Visible="true" AllowFiltering="true" FilterDelay="1000" AutoPostBackOnFilter="true" CurrentFilterFunction="EqualTo" ShowFilterIcon="false" FilterControlWidth="95%">
<HeaderStyle Width="60px"></HeaderStyle>
<ItemStyle Width="60px"></ItemStyle>
</telerik:GridBoundColumn>
<telerik:GridTemplateColumn DataField="Freight" HeaderText="Freight"
SortExpression="Freight" UniqueName="Freight" ReadOnly="false" Visible="true" HeaderStyle-Width="75px" ItemStyle-Width="75px" AllowFiltering="true" FilterDelay="1000" CurrentFilterFunction="EqualTo" ShowFilterIcon="false" FilterControlWidth="95%">
<ItemTemplate>
<asp:Label ID="lblFreight" runat="server" Text='<%# Eval("Freight","{0:c}") %>' />
</ItemTemplate>
<EditItemTemplate>
<telerik:RadNumericTextBox incrementsettings-interceptarrowskeys="false" incrementsettings-interceptmousewheel="false" ID="txtFreight" runat="server" Type="currency" width="100%" EmptyMessageStyle-Width="70px" Dbvalue='<%# Eval("Freight") %>'></telerik:RadNumericTextBox>
</EditItemTemplate>
</telerik:GridTemplateColumn>
<telerik:GridBoundColumn DataField="LoadNoAlpha" DataType="" HeaderText="Alpha"
SortExpression="LoadNoAlpha" UniqueName="LoadNoAlpha" ReadOnly="false" Visible="true" ColumnEditorID="edi80px" AllowFiltering="true" FilterDelay="1000" CurrentFilterFunction="EqualTo" ShowFilterIcon="false" FilterControlWidth="95%" >
<HeaderStyle Width="90px"></HeaderStyle>
<ItemStyle Width="90px"></ItemStyle>
</telerik:GridBoundColumn>
<telerik:GridTemplateColumn DataField="LoadNo" HeaderText="LoadNo"
SortExpression="LoadNo" UniqueName="LoadNo" ReadOnly="false" Visible="true" HeaderStyle-Width="90px" ItemStyle-Width="90px" AllowFiltering="true" FilterDelay="1000" CurrentFilterFunction="EqualTo" ShowFilterIcon="false" FilterControlWidth="95%">
<ItemTemplate>
<asp:Label ID="lblLoadNo" runat="server" Text='<%# Eval("LoadNo") %>' />
</ItemTemplate>
<EditItemTemplate>
<telerik:RadNumericTextBox incrementsettings-interceptarrowskeys="false" incrementsettings-interceptmousewheel="false" ID="txtLoadNo" runat="server" Type="number" width="100%" NumberFormat-DecimalDigits="0" NumberFormat-GroupSeparator="" invalidstyleduration="100" Dbvalue='<%# Eval("LoadNo") %>'></telerik:RadNumericTextBox>
</EditItemTemplate>
</telerik:GridTemplateColumn>
<telerik:GridTemplateColumn DataField="Quantity" HeaderText="Quantity"
SortExpression="Quantity" UniqueName="Quantity" ReadOnly="false" Visible="true" HeaderStyle-Width="90px" ItemStyle-Width="90px" ItemStyle-BackColor="#FFFFCC" AllowFiltering="true" FilterDelay="1000" CurrentFilterFunction="EqualTo" ShowFilterIcon="false" FilterControlWidth="95%" >
<ItemTemplate >
<asp:Label ID="lblQuantity" runat="server" Text='<%# Eval("Quantity") %>' />
</ItemTemplate>
<EditItemTemplate>
<telerik:RadNumericTextBox incrementsettings-interceptarrowskeys="false" incrementsettings-interceptmousewheel="false" ID="txtQuantity" NumberFormat-DecimalDigits="3" runat="server" Type="number" width="100%" NumberFormat-GroupSeparator="" invalidstyleduration="100" Dbvalue='<%# Eval("Quantity") %>' >
</telerik:RadNumericTextBox>
</EditItemTemplate>
</telerik:GridTemplateColumn>
<telerik:GridTemplateColumn DataField="DateReceived" HeaderText="Date Received"
SortExpression="DateReceived" UniqueName="DateReceived" ReadOnly="false" Visible="true" HeaderStyle-Width="90px" ItemStyle-Width="90px" AllowFiltering="false" FilterDelay="1000" CurrentFilterFunction="EqualTo" ShowFilterIcon="false" FilterControlWidth="95%" ItemStyle-BackColor="#FFFFCC">
<ItemTemplate>
<asp:Label ID="lblDateReceived" runat="server" Text='<%# Eval("DateReceived","{0:M/dd/yyyy}") %>' />
</ItemTemplate>
<EditItemTemplate>
<telerik:RadTextBox runat="server" Text='<%# Eval("DateReceived","{0:M/d/yyyy}") %>' Width="100%" ID="txtDateReceived" ></telerik:RadTextBox>
</EditItemTemplate>
</telerik:GridTemplateColumn>
<telerik:GridButtonColumn DataTextFormatString="Delete {0}"
ButtonType="ImageButton" UniqueName="DeleteRow" HeaderText=""
ItemStyle-HorizontalAlign="Center" HeaderStyle-HorizontalAlign="Center" CommandName="DeleteRow"
DataTextField="LoadID" ImageUrl="Images/Delete.gif" ShowInEditForm="true" ConfirmText="Delete this load?" ConfirmDialogType="RadWindow" ConfirmTitle="Delete Row">
<HeaderStyle Width="45px" />
<ItemStyle Width="45px" />
</telerik:GridButtonColumn>
</Columns>
<EditFormSettings>
<EditColumn FilterControlAltText="Filter EditCommandColumn column"></EditColumn>
</EditFormSettings>
</MasterTableView>
<ClientSettings AllowKeyboardNavigation="false">
<ClientEvents OnKeyPress="CatchKeyPress" ></ClientEvents>
<Selecting AllowRowSelect="true" />
<Scrolling AllowScroll="true" UseStaticHeaders="true" />
</ClientSettings>
<GroupingSettings CaseSensitive="false" />
<EditItemStyle BackColor="White" />
</telerik:RadGrid>
<telerik:GridTextBoxColumnEditor ID="ediFreight" runat="server" TextBoxStyle-Width="70px">
</telerik:GridTextBoxColumnEditor>
<telerik:GridTextBoxColumnEditor ID="ediQuantity" runat="server" TextBoxStyle-Width="70px"></telerik:GridTextBoxColumnEditor>
<telerik:GridTextBoxColumnEditor ID="edi80px" runat="server" TextBoxStyle-Width="80px"></telerik:GridTextBoxColumnEditor>
<telerik:GridTextBoxColumnEditor ID="ediTest" runat="server" TextBoxStyle-Width="40px"></telerik:GridTextBoxColumnEditor>
<telerik:GridDateTimeColumnEditor ID="ediDateReceived" runat="server" TextBoxStyle-Width="90px" ></telerik:GridDateTimeColumnEditor>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:csPrairielandAg %>"
DeleteCommand="DELETE FROM [tblLoads] WHERE [LoadID] = @LoadID"
InsertCommand="INSERT INTO [tblLoads] ([PONumber], [LoadNoAlpha], [LoadNo], [Freight], [Quantity], [Quarter], [Year], [DateReceived]) VALUES (@PONumber, @LoadNoAlpha, @LoadNo, @Freight, @Quantity, @Quarter, @Year, @DateReceived)"
ProviderName="<%$ ConnectionStrings:csPrairielandAg.ProviderName %>"
SelectCommand="SELECT a.LoadID, d.SupplierName,c.CompanyName, a.PONumber,a.Freight, a.LoadNoAlpha, a.LoadNo, a.Quantity, a.DateReceived,Quarter,Year FROM dbo.tblLoads AS a LEFT OUTER JOIN dbo.tblPurchases AS b ON a.PONumber = b.PONumber LEFT OUTER JOIN dbo.tblMembers AS c ON b.MemberID = c.MemberId LEFT OUTER JOIN dbo.tblSupplier AS d ON b.SupplierID = d.SupplierID WHERE (a.Quantity IS NULL) AND (b.Completed = 0) ORDER BY a.PONumber, a.LoadNoAlpha, a.LoadNo"
UpdateCommand="UPDATE dbo.tblLoads SET Freight = @Freight, LoadNoAlpha = @LoadNoAlpha, LoadNo = @LoadNo, Quantity = @Quantity, Quarter = @Quarter, Year = @Year, DateReceived = @DateReceived WHERE (LoadID = @LoadID)">
<DeleteParameters>
<asp:Parameter Name="LoadID" Type="Int32" />
</DeleteParameters>
<InsertParameters>
<asp:Parameter Name="PONumber" Type="Int32" />
<asp:Parameter Name="LoadNoAlpha" Type="String" />
<asp:Parameter Name="LoadNo" Type="Int32" />
<asp:Parameter Name="Freight" Type="Decimal" />
<asp:Parameter Name="Quantity" Type="Decimal" />
<asp:Parameter Name="Quarter" Type="Int16" />
<asp:Parameter Name="Year" Type="Int16" />
<asp:Parameter Name="DateReceived" Type="DateTime" />
</InsertParameters>
<UpdateParameters>
<asp:Parameter Name="Freight" Type="Decimal" />
<asp:Parameter Name="LoadNoAlpha" Type="String" />
<asp:Parameter Name="LoadNo" Type="Int32" />
<asp:Parameter Name="Quantity" Type="Decimal" />
<asp:parameter Name="Quarter" Type="Int16" />
<asp:parameter Name="Year" Type="Int16" />
<asp:Parameter Name="DateReceived" Type="DateTime" />
<asp:Parameter Name="LoadID" Type="Int32" />
</UpdateParameters>
</asp:SqlDataSource>
<br />
</div>
</asp:Content>

aspx.vb code:
Imports System
Imports System.Data
Imports System.Configuration
Imports System.Collections
Imports System.Web
Imports System.Web.Security
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.WebControls.WebParts
Imports System.Web.UI.HtmlControls
Imports Telerik.Web.UI
Imports System.Data.OleDb
Imports System.Data.SqlClient
Imports System.Collections.Generic
Imports System.Data.Common
Imports System.Diagnostics
Imports System.ComponentModel
Imports System.Web.SessionState
Imports System.Web.Mail
Imports System.Net.Mail
Imports System.Xml
Partial Public Class AddTonnage
    Inherits System.Web.UI.Page
    Dim strMode As String = ""
    Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
        Dim strYear As Integer
        Dim strMonth As Integer
        Dim strQuarter As Integer
        For i As Integer = 0 To RadGrid1.PageSize - 1
            RadGrid1.EditIndexes.Add(i)
        Next
        If strMonth >= 1 And strMonth <= 3 Then
            strQuarter = 1
        ElseIf strMonth >= 4 And strMonth <= 6 Then
            strQuarter = 2
        ElseIf strMonth >= 7 And strMonth <= 9 Then
            strQuarter = 2
        Else
            strQuarter = 4
        End If
        strYear = Year(Now())
        txtQuarter.Text = strQuarter
        txtYear.Text = strYear
        ' RadGrid1.Enabled = True
    End Sub
 
    Protected Sub RadAjaxManager1_AjaxRequest(sender As Object, e As AjaxRequestEventArgs)
        'For i As Integer = 0 To RadGrid1.PageSize
        '    RadGrid1.EditIndexes.Add(i)
        'Next
        If RadGrid1.Enabled = True Then
            If RadGrid1.Items.Item(1).IsInEditMode = True Then
                RadGrid1.Items.Item(1).FireCommandEvent("Update", String.Empty)
                'e.Item.FireCommandEvent("Update", String.Empty)
            End If
        End If
        RadGrid1.Rebind()
 
    End Sub
 
 
    Protected Sub RadGrid1_ItemCommand(sender As Object, e As Telerik.Web.UI.GridCommandEventArgs) Handles RadGrid1.ItemCommand
        '    Dim dv As System.Data.DataView = DirectCast(SqlDataSource1.[Select](DataSourceSelectArguments.Empty), DataView)
        If e.CommandName = "DeleteRow" Then
            Dim image As ImageButton = DirectCast(e.CommandSource, ImageButton)
            Dim strLoadID = image.AlternateText.ToString
            strLoadID = Replace(strLoadID, "Delete ", "")
            Try
                Dim deleteQuery As String = "Delete from tblLoads where LoadID='" & strLoadID & "'"
                Dim strConn As String = ConfigurationManager.ConnectionStrings("csPrairielandAg").ConnectionString
                Using connection As New SqlConnection(strConn)
                    connection.Open()
                    Using Command As New SqlCommand(deleteQuery, connection)
                        Command.CommandType = Data.CommandType.Text
                        Command.CommandText = deleteQuery
                        Command.ExecuteNonQuery()
                    End Using
                    connection.Close()
                End Using
                RadGrid1.Rebind()
            Catch ex As Exception
                Label1.Text = ex.Message
                Label1.Visible = True
 
            End Try
        End If
 
        If e.CommandName = "CopyPaste" Then
            Dim image As ImageButton = DirectCast(e.CommandSource, ImageButton)
            Dim strLoadID = image.AlternateText.ToString
            strLoadID = Replace(strLoadID, "Copy ", "")
 
            'Dim gd As GridDataItem = DirectCast(e.Item, GridDataItem)
 
            Dim str As String = strLoadID
            Dim LoadsData As New DataSet()
            Dim ConnString As String = ConfigurationManager.ConnectionStrings("csPrairielandAg").ConnectionString
            Dim conn As New SqlConnection(ConnString)
            Dim adapter As New SqlDataAdapter()
            adapter.SelectCommand = New SqlCommand("SELECT LoadID,PONumber,Freight,  LoadNoAlpha, LoadNo, Quantity,  DateReceived,Quarter,Year FROM dbo.tblLoads  ", conn)
            adapter.Fill(LoadsData, "tblLoads")
 
            Dim dt As DataTable = LoadsData.Tables("tblLoads")
            Dim rows As DataRow() = dt.[Select]("LoadID=" & str)
            Dim row As DataRow = dt.NewRow()
            'row[0] = number; set the Primary key to desired
            For i As Integer = 1 To dt.Columns.Count - 8
                row(i) = rows(0)(i)
            Next
            dt.Rows.Add(row)
            Dim cmdb As New SqlCommandBuilder(adapter)
            adapter.Update(LoadsData, "tblLoads")
            RadGrid1.Rebind()
            strMode = "Cancel"
        End If
 
        If e.CommandName = "RefreshGrid" Then
 
            'For i As Integer = 0 To RadGrid1.PageSize
            '    RadGrid1.EditIndexes.Add(i)
            'Next
 
            strMode = "Refresh"
            e.Item.OwnerTableView.Rebind()
            For Each dataItem As GridDataItem In RadGrid1.MasterTableView.Items
                dataItem.Edit = True
                Dim QuantityField As RadNumericTextBox = DirectCast(dataItem("Quantity").FindControl("txtQuantity"), RadNumericTextBox)
                If dataItem.ItemIndex >= 0 AndAlso dataItem.ItemIndex < RadGrid1.MasterTableView.Items.Count - 1 Then
                    QuantityField.Attributes.Add("onkeydown", "return setFocus2('" + TryCast(RadGrid1.MasterTableView.Items(dataItem.ItemIndex + 1)("Quantity").Controls(1), RadNumericTextBox).ClientID + "','" + DirectCast(dataItem("Quantity").FindControl("txtQuantity"), RadNumericTextBox).ClientID + "','" + DirectCast(dataItem("DateReceived").FindControl("txtDateReceived"), RadTextBox).ClientID + "', event);")
                ElseIf dataItem.ItemIndex = RadGrid1.MasterTableView.Items.Count - 1 Then
                    QuantityField.Attributes.Add("onkeydown", "lastFocus('" + DirectCast(dataItem("DateReceived").FindControl("txtDateReceived"), RadTextBox).ClientID + "', event);")
                End If
            Next
 
        ElseIf e.CommandName = "SaveChanges" Then
            RadGrid1_UpdateCommand(sender, e)
            e.Item.OwnerTableView.Rebind()
            strMode = "Save"
 
        ElseIf e.CommandName = "CancelChanges" Then
            strMode = "Cancel"
            ' RadGrid1.EditIndexes.Clear()
            e.Item.OwnerTableView.Rebind()
        ElseIf e.CommandName = "Sort" Then
            RadGrid1_UpdateCommand(sender, e)
            strMode = "Sort"
        ElseIf e.CommandName = "Page" Or e.CommandName = "Filter" Then
            RadGrid1_UpdateCommand(sender, e)
            strMode = "Page"
 
        ElseIf e.CommandName = "ChangePageSize" Then
            RadGrid1_UpdateCommand(sender, e)
            RadGrid1.EditIndexes.Clear()
            'RadGrid1.Rebind()
        End If
 
 
    End Sub
 
 
 
    Protected Sub RadGrid1_PageIndexChanged(sender As Object, e As Telerik.Web.UI.GridPageChangedEventArgs) Handles RadGrid1.PageIndexChanged
        If RadGrid1.Items.Item(1).IsInEditMode = True Then
            e.Item.FireCommandEvent("Update", String.Empty)
        End If
        'For i As Integer = 0 To RadGrid1.PageSize
        '    RadGrid1.EditIndexes.Add(i)
        'Next
        'RadGrid1.EditIndexes.Clear()
        'RadGrid1.Rebind()
    End Sub
 
    Protected Sub RadGrid1_PageSizeChanged(sender As Object, e As Telerik.Web.UI.GridPageSizeChangedEventArgs) Handles RadGrid1.PageSizeChanged
        If RadGrid1.Items.Item(1).IsInEditMode = True Then
            e.Item.FireCommandEvent("Update", String.Empty)
        End If
    End Sub
 
    Protected Sub RadGrid1_PreRender(sender As Object, e As System.EventArgs) Handles RadGrid1.PreRender
 
        For i As Integer = 0 To RadGrid1.Items.Count
            RadGrid1.EditIndexes.Add(i)
        Next
        RadGrid1.Rebind()
        For Each dataItem As GridDataItem In RadGrid1.MasterTableView.Items
            Dim QuantityField As RadNumericTextBox = DirectCast(dataItem("Quantity").FindControl("txtQuantity"), RadNumericTextBox)
            If dataItem.ItemIndex >= 0 AndAlso dataItem.ItemIndex < RadGrid1.MasterTableView.Items.Count - 1 Then
                QuantityField.Attributes.Add("onkeydown", "return setFocus2('" + TryCast(RadGrid1.MasterTableView.Items(dataItem.ItemIndex + 1)("Quantity").Controls(1), RadNumericTextBox).ClientID + "','" + DirectCast(dataItem("Quantity").FindControl("txtQuantity"), RadNumericTextBox).ClientID + "','" + DirectCast(dataItem("DateReceived").FindControl("txtDateReceived"), RadTextBox).ClientID + "', event);")
            ElseIf dataItem.ItemIndex = RadGrid1.MasterTableView.Items.Count - 1 Then
                QuantityField.Attributes.Add("onkeydown", "lastFocus('" + DirectCast(dataItem("DateReceived").FindControl("txtDateReceived"), RadTextBox).ClientID + "', event);")
            End If
        Next
        'RadGrid1.Rebind()
 
        Label1.Visible = "False"
    End Sub
 
 
 
 
 
    Protected Sub RadGrid1_UpdateCommand(sender As Object, e As Telerik.Web.UI.GridCommandEventArgs) Handles RadGrid1.UpdateCommand
        If txtQuarter.Text <> "" And txtYear.Text <> "" Then
            If RadGrid1.Items.Count > 0 Then
                If RadGrid1.Items.Item(1).IsInEditMode = True Then
                    For Each dataItem As GridDataItem In RadGrid1.MasterTableView.Items
                        Dim newValues As New Hashtable()
                        Dim eeditedItem As GridEditableItem = TryCast(e.Item, GridEditableItem)
                        Dim intLoadID As Integer = dataItem.OwnerTableView.DataKeyValues(dataItem.ItemIndex)("LoadID")
                        'Dim EmployeeID As String = eeditedItem.OwnerTableView.DataKeyValues(eeditedItem.ItemIndex)("EmployeeID").ToString()
                        RadGrid1.MasterTableView.ExtractValuesFromItem(newValues, dataItem)
                        'Dim BoundColumnValue As String = dataItem("txt").Text
                        Dim txtFreight As RadNumericTextBox = DirectCast(dataItem("Freight").FindControl("txtFreight"), RadNumericTextBox)
                        Dim txtLoadNo As RadNumericTextBox = DirectCast(dataItem("LoadNo").FindControl("txtLoadNo"), RadNumericTextBox)
                        Dim txtQuantity As RadNumericTextBox = DirectCast(dataItem("Quantity").FindControl("txtQuantity"), RadNumericTextBox)
                        Dim txtDateReceived As RadTextBox = DirectCast(dataItem("DateReceived").FindControl("txtDateReceived"), RadTextBox)
                        SqlDataSource1.UpdateParameters("LoadID").DefaultValue = intLoadID
                        SqlDataSource1.UpdateParameters("LoadNoAlpha").DefaultValue = newValues("LoadNoAlpha")
                        SqlDataSource1.UpdateParameters("LoadNo").DefaultValue = txtLoadNo.Text
                        SqlDataSource1.UpdateParameters("Freight").DefaultValue = txtFreight.Text
                        SqlDataSource1.UpdateParameters("Quantity").DefaultValue = txtQuantity.Text
                        SqlDataSource1.UpdateParameters("Quarter").DefaultValue = txtQuarter.Text
                        SqlDataSource1.UpdateParameters("Year").DefaultValue = txtYear.Text
                        SqlDataSource1.UpdateParameters("DateReceived").DefaultValue = txtDateReceived.Text
                        Try
 
                            SqlDataSource1.Update()
 
                            '  RadGrid1.EditIndexes.Clear()
                        Catch ex As Exception
                            SetMessage(Server.HtmlEncode("Unable to update Load. Reason: " + ex.StackTrace).Replace("'", "'").Replace(vbCrLf, "<br />"))
                        End Try
                    Next
 
                Else
                    Exit Sub
                End If
            Else
                SetMessage(Server.HtmlEncode("Quarter and Year is required."))
                RadGrid1.Enabled = False
            End If
        End If
        RadGrid1.Rebind()
        RadGrid1.Enabled = True
    End Sub
    Private Sub SetMessage(ByVal message As String)
        Label1.Text = String.Format("<span style='color:red'>{0}</span>", message)
    End Sub
 
 
    Protected Sub btnGrid_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnGrid.Click
        Dim strMessage As String = ""
        Dim strYear As Integer
        Dim strMonth As Integer
        Dim strQuarter As Integer
        If txtQuarter.Text = "" Or txtYear.Text = "" Then
            lblQuarterYear.Text = "Please enter a valid Quarter and Year to enable the grid."
            lblQuarterYear.ForeColor = Drawing.Color.Red
            lblQuarterYear.Visible = "true"
        Else
            strMonth = Month(Now())
            If strMonth >= 1 And strMonth <= 3 Then
                strQuarter = 1
            ElseIf strMonth >= 4 And strMonth <= 6 Then
                strQuarter = 2
            ElseIf strMonth >= 7 And strMonth <= 9 Then
                strQuarter = 2
            Else
                strQuarter = 4
            End If
            If strQuarter <> txtQuarter.Text Then
                strMessage = "Quarter entered is not the current Quarter. "
            End If
            strYear = Year(Now())
            If strYear <> txtYear.Text Then
                If strMessage = "" Then
                    strMessage = "Year entered is not the current Year"
                Else
                    strMessage = strMessage + "Year entered is not the current Year"
                End If
 
            End If
            If strMessage <> "" Then
                lblQuarterYear.Text = strMessage
                lblQuarterYear.Visible = True
            End If
            RadGrid1.EditIndexes.Clear()
            RadGrid1.Enabled = True
 
            For i As Integer = 0 To RadGrid1.PageSize
                RadGrid1.EditIndexes.Add(i)
            Next
            For Each dataItem As GridDataItem In RadGrid1.MasterTableView.Items
                Dim QuantityField As RadNumericTextBox = DirectCast(dataItem("Quantity").FindControl("txtQuantity"), RadNumericTextBox)
                If dataItem.ItemIndex >= 0 AndAlso dataItem.ItemIndex < RadGrid1.MasterTableView.Items.Count - 1 Then
                    QuantityField.Attributes.Add("onkeydown", "return setFocus2('" + TryCast(RadGrid1.MasterTableView.Items(dataItem.ItemIndex + 1)("Quantity").Controls(1), RadNumericTextBox).ClientID + "','" + DirectCast(dataItem("Quantity").FindControl("txtQuantity"), RadNumericTextBox).ClientID + "','" + DirectCast(dataItem("DateReceived").FindControl("txtDateReceived"), RadTextBox).ClientID + "', event);")
                ElseIf dataItem.ItemIndex = RadGrid1.MasterTableView.Items.Count - 1 Then
                    QuantityField.Attributes.Add("onkeydown", "lastFocus('" + DirectCast(dataItem("DateReceived").FindControl("txtDateReceived"), RadTextBox).ClientID + "', event);")
                End If
            Next
 
            strMode = "Refresh"
            'RadGrid1.Columns(0).Visible = False
            'RadGrid1.Columns(10).Visible = False
            'RadGrid1.Rebind()
        End If
    End Sub
 
 
 
End Class


2 Answers, 1 is accepted

Sort by
0
Vasil
Telerik team
answered on 19 Nov 2012, 12:52 PM
Hello Andy,

I don't see a reason in your code for the loading panel to fail showing. I am unable to run your code here, but in sample scenarios like the below, it is working correct.

<telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">
    <script type="text/javascript">
 
        window.onbeforeunload = function (evt)
        {
            evt.preventDefault(true);
            $find("<%=RadAjaxManager1.ClientID %>").ajaxRequest();
 
        }
    </script>
</telerik:RadCodeBlock>
 
<telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
    <AjaxSettings>
        <telerik:AjaxSetting AjaxControlID="Button1">
            <UpdatedControls>
                <telerik:AjaxUpdatedControl ControlID="Button1" LoadingPanelID="LoadingPanel1" />
            </UpdatedControls>
        </telerik:AjaxSetting>
    </AjaxSettings>
</telerik:RadAjaxManager>
<telerik:RadAjaxLoadingPanel runat="server" ID="LoadingPanel1" Skin="Default"></telerik:RadAjaxLoadingPanel>
 
<asp:Button runat="server" ID="Button1" />

Do you get any JavaScript error that might break the showing of the panel? Do you have the same issue in all browsers? If you could insulate the problem in sample runnable code I will try to debug it further.


All the best,
Vasil
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
ADT
Top achievements
Rank 1
answered on 19 Nov 2012, 03:06 PM
Not sure what was causing the problem, but I modified my code a bit. I added an "onchange" event to the PreRender ...
Protected Sub RadGrid1_PreRender(sender As Object, e As System.EventArgs) Handles RadGrid1.PreRender
 
    For i As Integer = 0 To RadGrid1.Items.Count
        RadGrid1.EditIndexes.Add(i)
    Next
    RadGrid1.Rebind()
    For Each dataItem As GridDataItem In RadGrid1.MasterTableView.Items
        Dim QuantityField As RadNumericTextBox = DirectCast(dataItem("Quantity").FindControl("txtQuantity"), RadNumericTextBox)
        Dim DateReceivedField As RadTextBox = DirectCast(dataItem("DateReceived").FindControl("txtDateReceived"), RadTextBox)
        Dim FreightField As RadNumericTextBox = DirectCast(dataItem("Freight").FindControl("txtFreight"), RadNumericTextBox)
        Dim AlphaField As TextBox = DirectCast(dataItem("LoadNoAlpha").Controls(0), TextBox)
        Dim LoadNoField As RadNumericTextBox = DirectCast(dataItem("LoadNo").FindControl("txtLoadNo"), RadNumericTextBox)
        QuantityField.Attributes.Add("onchange", "return updateEdit();")
        DateReceivedField.Attributes.Add("onchange", "return updateEdit();")
        FreightField.Attributes.Add("onchange", "return updateEdit();")
        AlphaField.Attributes.Add("onchange", "return updateEdit();")
        LoadNoField.Attributes.Add("onchange", "return updateEdit();")
        If dataItem.ItemIndex >= 0 AndAlso dataItem.ItemIndex < RadGrid1.MasterTableView.Items.Count - 1 Then
            QuantityField.Attributes.Add("onkeydown", "return setFocus2('" + TryCast(RadGrid1.MasterTableView.Items(dataItem.ItemIndex + 1)("Quantity").Controls(1), RadNumericTextBox).ClientID + "','" + DirectCast(dataItem("Quantity").FindControl("txtQuantity"), RadNumericTextBox).ClientID + "','" + DirectCast(dataItem("DateReceived").FindControl("txtDateReceived"), RadTextBox).ClientID + "', event);")
        ElseIf dataItem.ItemIndex = RadGrid1.MasterTableView.Items.Count - 1 Then
            QuantityField.Attributes.Add("onkeydown", "lastFocus('" + DirectCast(dataItem("DateReceived").FindControl("txtDateReceived"), RadTextBox).ClientID + "', event);")
        End If
    Next
    Label1.Visible = "False"
End Sub

and then modified my javascript to add a variable. If the variable is true it will run the ajax... otherwise it will not./
function gridCommand(sender, args) {
    var command = args.get_commandName();
    if (command == "DeleteRow" || command == "CopyPaste" || command == "SaveChanges" || command == "CancelChanges" || command == "Sort" || command == "Page" || command == "Filter" || command=="ChangePageSize") {
        //cancel the additional check in body.onunload
        window.editInProgress = false;
    }
}
function gridCommandCustom(evt) {
    var command = evt
    if (command == "DeleteRow" || command == "CopyPaste" || command == "SaveChanges" || command == "CancelChanges" || command == "Sort" || command == "Page" || command == "Filter" || command == "ChangePageSize") {
        //cancel the additional check in body.onunload
        window.editInProgress = false;
    }
}
function verifyCancelChanges() {
    if (window.editInProgress) {
        //alert(window.editInProgress.tostring);
        $find("<%=RadAjaxManager1.ClientID %>").ajaxRequest();
    }
 
}
function updateEdit() {
    window.editInProgress = true;
    window.onbeforeunload = function (evt) {
   // alert(window.editInProgress);
    verifyCancelChanges();
 
}

I also added  OnClientClick to my custom commanditemtemplate's
               <CommandItemTemplate>
                
                
         <table width="100%">
         <tr>
           <td align="right"><asp:LinkButton ID="btnCancelChanges" runat="server" OnClientClick="gridCommandCustom('CancelChanges');" CommandArgument="CancelChanges" CommandName="CancelChanges" Visible="true"><img style="border:0px" alt="" src="Images/Cancel.gif" />- Clear all Changes </asp:LinkButton>      
<asp:LinkButton ID="btnSaveChanges" runat="server" CommandArgument="SaveChanges" CommandName="SaveChanges"  OnClientClick="gridCommandCustom('SaveChanges');" Visible="true"><img style="border:0px" alt="" src="Images/Update.gif" />- Save All changes</asp:LinkButton>
 
</td>
         </tr>
         </table>              
 
            
           </CommandItemTemplate>

and an OnCommand event to my clientevents.
<ClientEvents OnKeyPress="CatchKeyPress" OnCommand="gridCommand" ></ClientEvents>


From what I can tell, every item command argument runs the window.onbeforeunload event so possibly adding evt.preventdefault(true) to my onbeforeunload may take care of it, but I have it functioning now as needed. Actually solved it last night before seeing this post.





Tags
Grid
Asked by
ADT
Top achievements
Rank 1
Answers by
Vasil
Telerik team
ADT
Top achievements
Rank 1
Share this question
or