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

session variable lost after postback

5 Answers 935 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Boris
Top achievements
Rank 1
Boris asked on 18 Aug 2012, 03:02 PM
Hi all,
1. I have the Radgrid having updatable datasource (List<T>) that I store in the session's variable after updating/inserting.
2. All works OK excepting one thing:
3. Each time when I change the C# or aspx - add/remove some control, for example) first time after change the datasource extracted from session is null (when I want edit some row/insert new row)!
4, Second or more time (if I CHANGE NOTHING) all it's OK.

Can anybody give me prompt in this problem?
Thank you.

Boris


5 Answers, 1 is accepted

Sort by
0
O'Man
Top achievements
Rank 1
answered on 23 Aug 2012, 07:10 AM
hi

maybe your session data is not add in the right event in session. anytime you change .aspx code your project compiles and session cleared.

thanks,

omi
0
Boris
Top achievements
Rank 1
answered on 23 Aug 2012, 07:33 AM
Hi omi,
About which event you speak about RadGrid's event, or asp.net page event or some else?

Thank you
Boris
0
O'Man
Top achievements
Rank 1
answered on 28 Aug 2012, 07:22 AM
hi

right event depent on scenario. give some codes to show your scenario.

thanks
omi
0
Boris
Top achievements
Rank 1
answered on 28 Aug 2012, 08:17 AM
Hi omi,
the code is too big,
here I give the scenario when seswsion is lost:
1. start: Page load 
if {!IsPostBack)
{
    // get the data from database and save them in session
   Session["data"]=DataFromDB
}


2. Initiating Postback (f.e. clicking the pencil on the grid's row)
RadGrid1_ItemDataBound(...)
{
// pseudocode:
    If item is editable Item
    {
        data = Session["data"]
// HERE I getting empty session!
    }
}
0
O'Man
Top achievements
Rank 1
answered on 29 Aug 2012, 03:16 PM
hi

here my code all work expectet:

<%@ Page Language="C#" %>
 
<%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<script runat="server">
 
    protected void Page_Load()
    {
        if (!IsPostBack)
        {
            Session["data"] = "_SessionData_";
        }
    }
    protected void Omi_ItemDataBound(object sender, GridItemEventArgs e)
    {
        if (e.Item is GridEditableItem)
        {
            if (Session["data"] != null)
            {
                string data = Session["data"].ToString();
                Label1.Text += data;
            }
        }
    }
    protected void OmiGrid_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
    {
        OmiGrid.DataSource = new string[] { "1" };
    }
</script>
<head id="Head1" runat="server">
</head>
<body>
    <form id="mainForm" runat="server">
    <asp:ScriptManager runat="server" ID="ScriptManager1">
    </asp:ScriptManager>
    <asp:Label Text="" ID="Label1" runat="server" EnableViewState="false" />
    <telerik:RadGrid ID="OmiGrid" runat="server" AutoGenerateEditColumn="true" OnNeedDataSource="OmiGrid_NeedDataSource" OnItemDataBound="Omi_ItemDataBound">
        <MasterTableView CommandItemDisplay="Top">
            <Columns>
            </Columns>
        </MasterTableView>
    </telerik:RadGrid>
    </form>
</body>
</html>

thansk
omi
Tags
Grid
Asked by
Boris
Top achievements
Rank 1
Answers by
O'Man
Top achievements
Rank 1
Boris
Top achievements
Rank 1
Share this question
or