Showing posts with label session. Show all posts
Showing posts with label session. Show all posts

Wednesday, March 28, 2012

updates, both session and deserialisation

hi,

I'm new to the forum and Asp.net ajax but have been a c# dev for a while. My question is regarding using the session from within Ajax, and also to boot reading in a file.

the following pseudocode outlines my problem, the button and label are both in update panel. which itself is working fine (as on the 2nd click the session variable is shown)

basically,

button1 click set session["test"] = hello;

in the page load event have

if(session != null) label1 = session[hello];

what gets me is why when clicking a link (still within the update panel) the session variable is shown, but not through the original request. As I thought the entire page cycle is processed at the server and only the items in the update panel (in this case update mode is always) are refreshed?

the same happens with deserialization when used from the wizard in an update panel, it loads up the previous file rather than the new one but i imagine its somthing I have done wrong...

I have a quick fix with a timer set to 1second and calling my refresh function. I've also looked at using the Ajax profile for storing data i would else have stored in the session.

I was just wondering if anybody could point out my mistake or offer any alternatives. (using the membership and roles isnt feasable on this project unfortunatly)

well cheers and im sure it must be just somthing i have missed!

initiagroup:

As I thought the entire page cycle is processed at the server and only the items in the update panel (in this case update mode is always) are refreshed?

That's correct.

Your problem sounds like it almost has to be a page life cycle issue. Can you post a little bit more code?


thanks for your quick reply. Here is an extremly simple code snippit that shows my problem... its ok i think i have worked it out. Am i right in thinking that even without the update panel that code wouldnt work?

1<%@. Page Language="C#" AutoEventWireup="true" CodeFile="test.aspx.cs" Inherits="test" %>23<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">45<html xmlns="http://www.w3.org/1999/xhtml" >6<head runat="server">7 <title>Untitled Page</title>8</head>9<body>10 <form id="form1" runat="server">11 <asp:ScriptManager ID="ScriptManager1" runat="server">12 </asp:ScriptManager>13 <div>14 <asp:UpdatePanel ID="upd1" runat="server">15 <ContentTemplate>16 <asp:label ID="lbl1" runat="server"></asp:label>17 <asp:Button ID="btn1" runat="server" Text="click" OnClick="btn1_Click" />18 </ContentTemplate>19 </asp:UpdatePanel>20 </div>21 </form>22</body>23</html>

and the code behind

1using System;2using System.Data;3using System.Configuration;4using System.Collections;5using System.Web;6using System.Web.Security;7using System.Web.UI;8using System.Web.UI.WebControls;9using System.Web.UI.WebControls.WebParts;10using System.Web.UI.HtmlControls;1112public partialclass test : System.Web.UI.Page13{14protected void Page_Load(object sender, EventArgs e)15 {16if (Session["test"] !=null)17 {18 lbl1.Text = Session["test"].ToString();19 }20 }21protected void btn1_Click(object sender, EventArgs e)22 {23 Session["test"] ="test";24 }25}26

as you see very easy just click the button and see what happens. In debug it hits the page load event after the button is pressed.

oh and its just a standard ajax template from the new website dialog box.

Cheers.

Saturday, March 24, 2012

UpdatPanel and Session Variable

I have a treeview which populates a session variable when treeview items are selected. The session variable in turn is used to create a datatable. I have the datatable inside of an updatePanel and the trigger is the selectednodechanged event of the treeview. All of this works great. However, while the Session variable and resulting datatable are updated within the updatepanel the session variable is not updated/current when accessed by other controls/methods (that is- none of the treeview items placed inside of the session variable are there). Without the updatePanel changes to the session variable are "global" and seen by other callers. Is there any way to make the changes to the session variable that occur inside of the updatepanel "global"? Is there a way to place the session variable inside of the updatepanel?

Thanks in advance for any help or advice.

Hi rudolph41,

You should ask your question in the"Atlas" Discussion and Suggestions forum because that's where all theUpdatePanel experts are.

Thanks,
Ted

UploadPanel and Session problem

I have an UpdatePanel and a simple asp Button inside it, that produces asynchronous postbacks to server. Server-side onButton_Click event handling is a lasting operation(about 5 sec) thats why if async postback is in process user should be able to go to another page or make any actions.

Everything works fine unless the session object is used anywhere in application(not even in the button on click handler!). If session object is used IE doesnt allow you to make any type of postback while current async postback is in progress.

Has enyone encountered such a problem? Please Help!

Hi,

Asp.net is typical a multi-thread environment, and for thread safety, page requests using session state internally use a ReaderWriterLock to manage access to the session state.So, the second request will not be able to access it untill the lock by the previous request is released.

It should work if the second page doesn't make use of session or use <a> tag to perform redirection.


Hope this helps.