Using session variable instead of hidden fields in aspx pages - session

I would love to use hidden field value but I think I am missing something to do.
Since every page refresh or staying a little bir longer on the page, the value is missing.
ASP.NET MVC: Make Session entirely cookie-less (hidden form field)
? how can i do the this cookiles suff above...?
I use hidden value to keep the url to redirect to next page. May be i sould not keen on using hidden value, session variables are better?
Advices please.
Regards

If you want to keep something across the page refresh, you need to use a server side control with ViewState enabled. You have not made it clear whether for hidden fields, you are using any server side control or plain old html control. With html control, you shall have to manage the show for yourself.

Related

asp.net mvc3 persisting form data when user navigates to unrelated page

So a user fills out a form then decides to click on a unrelated link that happens to be on the page say to a disclaimer page. Then using internal site navigation (not the browser back button) comes back to the form he was on. The link back is an ActionLink.
What is the best way to keep his data on the form. I figure I'll have to serialize the data and save it. I can do a ajax call before going to the other page. I'm looking for the sexy solution. Something that will handle it on a global scale.
Is this even a standard practice?
HTTP is Stateless. You are trying to bring some Stateful nature it !
If you really want to keep the data, You can keep in the Session variable and access it there. You need to override the click event and (in javascript) send the form data to an action via jQuery ajax post where you store it into Session. You can access it later when you come back to this page.
Do you really want to do that ? I think 80 % people knows that once they click on another link, the data will go away. You could probably show some alert message to ask "Are you sure to leave this page" like stackoverflow does.

JSP includes and MVC pattern

I am new to JSP/Servlets/MVC and am writing a JSP page (using Servlets and MVC pattern) that displays information about recipies, and want the ability for users to "comment" on it too.
So for the Servlet, on doGet(), it grabs all the required info into a Model POJO and forwards the request on to a JSP View for rendering. That is working just fine.
I'd like the "comment" part to be a separate JSP, so on the RecipeView.jsp I can use to separate these views out. So I've made that, but am now a little stuck. The form in the CommentOnRecipe.jsp posts to a CommentAction servlet that handles the recording of the comment just fine. So when I reload the Recipe page, I can see the comment I just made.
I'd like to:
Reload the page automatically after commenting (no AJAX for now)
Block the user from making more than one comment on each Recipe over a 1 day timeframe (via a Cookie). So I store a cookie indicating the product ID whenever the user makes a comment, so we can check this later? How would it work in a MVC context?
Show a message to the user that they have already commented on the Recipe when they visit one
which they have commented on
I'm confused about using beans/including JSPs etc on how to achieve this.
I know in ASP.NET land, it would be a UseControl that I would place on a page, or in ASP.NET MVC, it would be a PartialView of some sort. I'm just confused with the way this works in a JSP/Servlets/MVC context.
you can use response.sendRedirect() or forward APIs in javax.servlet to redirect to a new page or refresh the same page (redirect to the same page/path so that the beans/data gets refreshed)
about restricting to one comment per day - yes you can use cookie but the problem is that user might use another browser type (chrome, FF, Safari) and will be able to make multiple comments.
Ideally you should store the lastCommentTime in the model/persistent store and tie it to the user information - this way your model object can expose an API that checks the last comment time and returns true/false depending on whether user can comment or not.
You can use this API in your servlet/JSP to show/hide the comment button, for example and also show a message

codeigniter loses session due to redirect, is there a way to regenerate it?

I've got a form that has, among other things, a preview button and a submit button. Let's say that the form contains a person's data. Clicking preview will submit the form to example.com/preview and get it opened in a new tab. The preview controller will insert the person's data in a table and, based on the value of LAST_INSERT_ID(), it will redirect to example.com/person/ID. When the redirect occurs, all session data is lost. I want to be able to keep session data so that, upon checking the example.com/person/ID page, the admin user can close it and do some changes to the form or submit it.
I've noticed that storing the session id in a flashdata item won't work, it won't get past the redirect. Also, if i somehow manage to get the session_id past the redirect (although adding it to the url is not what my client wants), I still don't know a way to regenerate the Codeigniter session with it. Another option I've looked into is using Codeigniter Native Session class, but the version I've found on the site is not for Codeigniter 2.0.0.3, and I'm afraid that using it might break something.
Any advice is much appreciated.
The solution was to change my ci_sessions database table fields' collations to utf8_general_ci (the default was latin1_swedish_ci)

Virtuemart Display Page after Remote redirect

I am aiming to create a payment module. Its users shall be redirected away from the site's URL in order for the transaction to be processed by a third party at a different URL. I would then like customers to be redirected back to a generic 'success' page that notifies them the order was a success. I have tried redirecting to the default success page (checkout.thankyou.php), but I get lots of errors; all the constants etc. that the application requires have obviously been lost during the redirect.
I would like to be able to retrieve the theme currently enabled in the configuration and use it to insert some basic HTML into the view. I would also like to access the database to perform some queries.
Can anybody advise? I am very stuck, and cannot find anything useful in the documentation! Thank you.
Can you be more specific about what type of information you want in your success page? If you just want basic HTML, then there's no reason you can't just write a basic Joomla article and redirect to that instead of trying to redirect to a VM partial. Again, if it's just basic HTML (no data from the transaction), then you can simply use a code inspector (like FireFox Inspect Element) to track down the CSS classes you like from the template and simply use them in your Joomla article to make it look like the VM template. You can find most of them in components/com_virtuemart/themes/default/themes.css.
If you need to display actual transaction data in your Thank You message, be prepared for a bit more work. You're probably going to have to write a cookie containing the record data BEFORE it gets sent offsite, and then read the cookie just prior to rendering the Thank You page.

What are my options for changing the querystring on a URL, and updating browser history?

Is there any way I can change the URL or add more history to the "back button" without having to refresh the entire page?
My application is AJAX based and I'd like to add some "undo" events to history so that the user can simply hit back and retain the old values.
What's possible today? I hear some of this may be in HTML5 but haven't checked whats supported in current browsers.
I think you can use window.location.hash to track the #part of the page, in your case, #state1, #state2 and so on.
window.location.hash = '#state' + (++ stateN) to set and
stateN = parseInt(window.location.hash.match(/\d+$/)[0])
See On - window.location.hash - Change? for more details about how to detect location hash changes.
You could use 301 redirection. Personally, I would use cookies on the client side, or sessions in your back end, to store the breadcrumbs. Storing state information in the URL is a bad idea for AJAX applications, because people might return to a url that the server side is not in the right state to respond to.
Another option would be to provide your own Back button that knows which page to go back to.
The answer for this question will be more or less the same as my answers for these questions:
How to show Ajax requests in URL?
How does Gmail handle back/forward in rich JavaScript?
In summary, two projects that you'll probably want to look at which explain the whole hashchange process and using it with ajax are:
jQuery History (using hashes to manage your pages state and bind to changes to update your page).
jQuery Ajaxy (ajax extension for jQuery History, to allow for complete ajax websites while being completely unobtrusive and gracefully degradable).
It is possible to use ASP.NET's built in Script Manager to update the browser's history. A full how-to to do this is located here:
http://www.asp.net/aspnet-in-net-35-sp1/videos/introduction-to-aspnet-ajax-history

Resources