ASP.NET Session variable not getting set on pages with Ajax extentions - c#

Another day, another silly, newbie ASP.NET question...
In my ASP.NET web application, I've chosen the method of setting session variables and redirecting, when I need to carry-over values when moving to a new page. This had been working perfectly fine, but then I added-in the AjaxControlToolkit. Now, on pages that contain controls from that tool kit, the session variables do not get set upon redirect. A very strange thing. I can't immediately think of anything that would be causing the problem, save for some sort of strange name-collision thing, but I've put that thought to rest by trying it with nonsense names.
Here's some code samples... All I'm doing is:
Session["SearchTermText"] = search_term;
Response.Redirect("SearchResult.aspx", false);
...in the master page code-behind. It was working fine, before, and still works perfectly on pages that don't have the Ajax tool kit controls. Very, very odd.
I know that the Ajax round trips aren't somehow resetting all my session variables, because some of the already-set session data (my log-in, for example) sticks, even on the pages with the Ajax tool kit controls.
Has anyone seen anything like this?

Related

JavaScript generated web page issue

I have a problem with javascript generated web page. I have a web page on the internet that is generated by javascript. I am working on changing a web page using wpf web browser control. I have to make some changes to the web page by inserting jquery, and changing css and hiding some elements.
Here is the issue.
Application works ok most of the time, but sometimes, for reasons unknown, it does not change the css or hides the elements. I presume that it has something to do with the javascript that actually generates the page. My code is executed, but no changes are made, so I presume that the script cannot find the elements in the page because they do not exist in the page, at the time of the execution of my scripts. This is just an assumption.
I need help resolving this issue. I have tried delaying the execution of my scripts for n seconds, waiting for body.ready, document.ready and window.ready, but nothing helped. Also, I use wpf web browsers LoadCompleted event, but... From time to time, the script simply makes no effect on the page. Did somebody have this issue, does anyone have any idea how to solve it?
Thank you very much in advance...
When building single page apps, always use a framework like Backbone or Sammy.js together with Mustachejs (or Hogan.js) for templating.
Since we don't have any code to look at, if you're using jQuery, I suggest you check out .live() and .on() for attaching event handlers to elements you plan on loading into a div (making them clickable) etc.

jQuery 'viewstate'-like behavior

I'm building a website in jquery mobile. It is a SOA application and on 'pageshow' event I call the web services get the data and populate labels and dropdown lists with it. However, say for instance, when a user clicks back and the app takes him back to dashboard, the ajax call is made again and the labels are unnecessarily populated again. What I want to ask is, can I prevent this behaviour of populating the same labels with the same data over and over again? Does jquery mobile have this 'viewstate' behavior built in?
Thank you for taking the time to answer my question.
You could use HTML5's localStorage / sessionStorage API to actually persist data between callbacks.
Personally I think that if you'd use JQM's page idiom (having only data-role=page and not loading any new ajax pages), you wouldn't have this problem at all (but rather the opposite, how to reset all fields).

Silverlight object seems to be auto-reloading

I have a rather complex web page structure containing a Silverlight control. The control loads and functions fine. However, sometimes the control seems to auto-reload itself. I'm not sure how, or why - and I'm fairly sure there's no external code in the web page that's causing it.
Basically, the way I noticed this is that the control contains some cached data. When it's created, the data is passed from JavaScript to the Silverlight control, which is then cached. The data is then deleted from the JavaScript side. Almost randomly, the Silverlight control throws an error saying there is no cached data. I found that this is because the control is re-loaded somehow - though not by JavaScript as the relevant area within JavaScript where the SL control is created is never hit a second time. But the Application_Startup event handler within the SL control is hit a second time.
Unfortunately, I cannot post the code as it is commercial and I have not yet managed to recreate this issue in a test project. I will post code if/when I do.
If that makes any sense, does anyone have any thoughts or suggestions on the matter?
You can see plugins auto reload when specific DOM elements change. Are you manipulating the DOM somehow?
Here's an example of it happening in Flash, though I've ran into the same issue with Silverlight. This is more of a Browser issue and not specific to Silverlight or Flash.
Stop reloading flash file when using show and hide methods

How to show the list of recently visited web pages as chrome does

I would like to display the list of recently accessed/visited web pages just as google chrome shows. I want to achieve this using C# and asp.net.
I am working on a site where the user can see the list of pages that they have visited, I tried using iframe but that does not work as per expectation. I am looking for a clean and intuitive interface something like google chrome.
I would like to provide a thumbnail view of the recently visited pages.
To keep my question simple, I want to display a list of urls as thumbnails, just as chrome does
Note that Chrome can do it easy, as they get to render the page and can take a bitmap snapshot of it easily to show for the thumbnails. (These are not live websites in there)
If you want to do the same thing, you have to render the website offscreen and take a snapshot to show to the user.
If you want to actually show a live website - now that's another story. There are a lot of sites that don't like being shown in the context of another website (for whatever reasons - security, marketing and so on) and will employ any tricks (including legal) to make sure this does not happen.
Pages only visited within your own app?
There are several components that will alow for that using their api. For example:
http://www.tonec.com/products/wssh/index.html
You can just take a snapshot after the DOM for tha page is completely generated and save the output using the tool on peruser basis.
Now, if you want something more generic that works for any web site, you'd probably want to go with a web browser plugin.
Here would be a possible solution, although I've not tried it personally:
Keep a record of all the pages that a user visits (e.g. in a database)
When the user visits a landing page on your site, you could call the WebBrowser.DrawToBitmap function to render a bitmap of each page they have visited recently.
Please note: this is just a theory, I'm not saying it will work! ;)
This link might help you get started:
http://pietschsoft.com/post/2008/07/c-generate-webpage-thumbmail-screenshot-image.aspx

What are the MUSTS for having an asp.Net application to support BACK button of the browser?

Is there any pattern or kind of "least requirements list" to follow for ensuring an asp.NET application to support BACK button of the browser for each aspx page?
thanks
In general, the back button on the browser will take you to the previous HTML GET or POST that occurred. It navigates by page-wide transactions, so anything done dynamically cannot be navigated that way. Also, the back button doesn't rewind code execution, so if you are determining something based off of a Session variable or something similar, that won't be rewound either. Obviously, it won't rewind database transactions either.
In general, if you want to support the back button, you'll need to make sure to divide everything you need to navigate between with said button is divided by an HTML transaction of some sort.
Again, you're going to run into issues if your page display is dependent on server-side control that changes from one post to the next. This is one reason you see some forms feed a 'Page has expired' error when you try to navigate back to them.
Not really... It depends on your application flow.
There are things that make supporting the back button more awkward.
for example using pure ajax to change the majority of the content on the page,
will look like a 'new' page but wont be compatible with the back button (though you can fudge it)
another example is posting back to the same page more than once, as this can make it appear like the back button is not working, and at the same time re-doing your request (and therefore database transactions)
Fundamentally it depends on your application requirements.

Categories