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

RadGrid Client side Binding loosing data on postback

1 Answer 53 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Pawan
Top achievements
Rank 1
Pawan asked on 15 Jul 2013, 06:07 PM
I have a Telerik RAD Grid which i am bindng on client side. i have another button(Button 2) which when clicked will do a postback and get the values of the grid and call the database to perform some activity, but in the Button 2 Click event, values of the grid are lost and also the grid after Button 2 click has empty data. See below sample code.
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="test1.aspx.cs" Inherits="WebApplication4.test1" %>
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head id="Head1" runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <script src="Scripts/jquery-1.4.1.min.js" type="text/javascript"></script>
        <script type="text/javascript">
 
    function test() {
                var EmployeeInfo = { "Emp_Number": "12349999" }
                var arr = [];
                arr.push(EmployeeInfo);
                grid = $find("<%=rdEmployeeInfo.ClientID %>");
 
                tableView = grid.get_masterTableView();
                tableView.set_dataSource(arr);
                tableView.dataBind();
            }
 
        </script>
        <asp:ScriptManager ID="ScriptManager1" runat="server">
        </asp:ScriptManager>
           <asp:button ID="Button1" runat="server" OnClientClick="test(); return false;" />
            <asp:button ID="Button2" runat="server" onclick="Button2_Click" />
        <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
            <br />
        <telerik:RadGrid ID="rdEmployeeInfo" runat="server" AutoGenerateColumns="false" AllowAutomaticInserts="false"
            AllowAutomaticUpdates="false" EnableAJAX="true" Width="100%" GridLines="None"
            PageSize="1" EnableViewState="true">
            <ItemStyle ForeColor="Orange" />
            <MasterTableView Width="100%" AutoGenerateColumns="false">
                <CommandItemSettings ShowAddNewRecordButton="false" ShowRefreshButton="false" />
                <Columns>
                    <telerik:GridBoundColumn DataField="Emp_Number" HeaderText="Employee Number" ReadOnly="true">
                    </telerik:GridBoundColumn>
                </Columns>
            </MasterTableView>
       
        </telerik:RadGrid>
    </div>
    </form>
</body>
</html>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Web.Services;
using Telerik.Web.UI;
 
namespace WebApplication4
{
    public partial class test1 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                DataTable dt = new DataTable();
                dt.Columns.Add("Emp_Number");
 
                rdEmployeeInfo.DataSource = dt;
                rdEmployeeInfo.DataBind();
            }
        }
 
      
 
        protected void Button2_Click(object sender, EventArgs e)
        {
 
        }
    }
}

1 Answer, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 1
answered on 17 Jul 2013, 12:31 PM
Hi Pawan,

When you have a button click,due to its postback the data's will be lost.Here you have bind the grid on client side,then trying to access it on server side on another button click.This will cause the postback and data will be lost.One suggestion is to do both, binding and other functions on the server side completely or do it completely in clientside.Mixing up is causing such issues.
Please let know if any concern.

Thanks,
Princy
Tags
Grid
Asked by
Pawan
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 1
Share this question
or