How to save property after tombstoning? - windows-phone-7

I have some property OwnerId that has each page in my application. I need these property to create HttpWebRequest and get some data. But when the application deactivated and activated again the page as deleted and created again, so these property is 0. I can't save these property in PhoneApplicationPage.State , because these property is different for different pages, so when I go twice back I can get error. I think to take it property after application activated from NavigationService.BackStack pages.But I'm not sure it is right. How can I do it ?

Aram .. thanks for explaining the question better.
Now, while your application is in the foreground, how are you managing all these different OwnerIDs? A collection? I am guessing you don't have multiple instances of the same page; but rather pass query parameters along to indicate which OwnerID/UserID should be used to display appropriate user info. You could put the whole collection in State dictionaries with a key & hydrate/dehydrate during the application lifecycle. Makes sense?
Thanks!

I'm not 100% clear on whether you need a setting for each page or just a single setting for the app. In either case your best option (IMO) is IsolatedStorageSettings (http://msdn.microsoft.com/en-us/library/system.io.isolatedstorage.isolatedstoragesettings(v=vs.95).aspx)
If you just need a single setting then there's no problem but if you need one for each page you will need to do something ugly like using the page name as the key.

Related

How do you pass unchecked checkbox value using Coldfusion.ajax.submitform?

I'm stumped. I have a <cfform> and I'm saving the form info to a database using a cfc and Coldfusion.Ajax.submitform. My form uses checkboxes. What I can't seem to figure out is how to capture if a checkbox is unchecked. I've read that if a checkbox is unchecked, it doesn't get sent with the form info. I've also read that you can use <cfparam> to give the checkbox a default value so that if the checkbox is unchecked, it will still have a value e.g. <cfparam name="form.checkbox1" default="0">. Unfortunately, it doesn't seem to work when I use ColdFusion.Ajax.submitForm. Any insight would be greatly appreciated. Thanks.
Creating a proper answer so you can close this question.
Per the ColdFusion documentation: http://help.adobe.com/en_US/ColdFusion/9.0/CFMLRef/WSc3ff6d0ea77859461172e0811cbec22c24-7faf.html
Cfparam tests for the existence of a parameter (that is, a variable),
validates its data, and, if a default value is not assigned,
optionally provides one.
Mostly it's just used to create a default value for a variable of pretty much any scope.
As you have discovered, the cfparam tag must be used when the variable is required, in the processing page. cfquery param creates the variable in memory on the coldfusion server and is only available for the duration of the request (unless you use it to set a value to a persistent scope like session or application). It does not create form elements or javascript variables

Setting Absolute Uri in MVC 3

Is it possible to set the absoluteURI in the controller after clicking on an action link? So for example:
User clicks on a link called "GoHere". The current URL is domain.com/section/place. When the link hits the method in the controller, it recognizes that the user is currently in a section called "section", even though in the file structure section doesn't exist. The link itself actually points to domain.com/place2. Instead of returning a URL of domain.com/place2, it returns domain.com/section/place2.
The reason I ask is because for what I'm doing, the section is completely arbitrary and doesn't exist. It's just there to give the impression that the user is in another section. I know I could create extra sets of controllers, but I'm trying to get around this since for management purposes it's better if I just have one set of controllers. Is this possible? Thanks.
In your gobal.asax, try setting your route to require section for the control. Maybe "{control}/section/{action}/" and whatever else you need.

When using Url.RouteUrl, the area is missing

I suspect I'm doing this wrong.
For various reasons, my app forces the user to make some choices right after login. In order to ensure that they enter the necessary data, I override the OnActionExecuting method in a base controller class to intercept any attempt at executing an action before this data has been entered, and redirect the user to the necessary page. I preserve the url of the action they were attempting to execute with the following code:
url = Url.RouteUrl("Default", filterContext.RouteData.Values);
(filterContext is an ActionExecutingContext object, and a parameter of OnActionExecuting.)
The problem I'm having is that, if the action was associated with a controller in an area, the url I get doesn't reflect the area.
I understand from other posts that I can get the area name from the DataTokens collection of RouteData. But I'm uncertain of the best way to pass it. I suppose I could retrieve it and use the RouteValueDictionary.Add method to add it to RouteData.Values (assuming Values is not read-only at that point; I don't know), but that feels a bit ... odd, like somehow the point is being missed.
Is this really the way this is supposed to be done? Is there something wrong elsewhere, that Area is absent from my RouteData.Values?
I would just take it out of the data tokens in the filter and add it to route values. You can do it with RouteValues.Add:
if (filterContext.RouteData.DataTokens.ContainsKey("area"))
filterContext.RouteData.Values.Add("area",
filterContext.RouteData.DataTokens["area"]);
The areas feature was added in MVC2, and I imagine this is a side effect of it not being in MVC1. However, as long as your RouteValues contains an "area" key, UrlHelper.RouteUrl should generate the correct URL for the area.

CoreData prevent delete of defaults

I have an entity in my coredata document based application.
I have certain default values that get created when a new document is created for that entity.
I need to be able to allow users to add and remove from that list (easily done), but prevent users from deleting the default values (cant find the answer).
Thanks for your response, that is a good option in this case I think I will use it.
I was wondering though if anyone knows how a person can VALIDATE a delete.... so if a person clicks on the delete button, it will go through some logic (complex or simple, depending on the application) then either ignore the click or actually delete the object.
I've looked at the method validateForDelete: but there is very little documentation on it and i'm not sure if this is the intended use of the method.
You could add a boolean attribute to your entity that indicates whether or not a value is a default. You could then deactivate the delete button if the currently selected value is a default, using the enabled binding.

where should I save a complex MVC application UI state?

I've been having a look at several MVC frameworks (like rails, merb, cakephp, codeignitier, and similars...)
All the samples I've seen are basically plain and simple CRUD pages, carrying all the infr needed in the querystring and the posted field values.
I've got a couple of apps made with some sort of framework built with classic asp.
This framework handles some CRUD stuff a little more complex than the examples I found.
Something like master-detail, filtering by example, paging, sorting and similars.
I have a controller class that it's just a finite state machine, that goes thru diferent states (like new, browse, filter, show, etc.), then performs the appropiate action depending on the event raised and finally retrieves the neede info to the calling page.
To achieve this I have several hidden inputs to keep the state of the web page (like current id, filter criterias, order criterias, previous state, previous event, well, you get the idea)
What do you think would be the finnest approach to achieve this kind of funcionality?
hidden inputs built in the view and used from the controller??? (I guess that would be the equivalent of what I'm doing right now in classi asp)
--
(added in response to tvanfosson)
basically, my question refers to the third category, the context-dependent setting (in respect to the other two categories I agree with you) the info I was storing in hidden fields to store them on the querystring, I guess that when you click on the "next page" you include everything you need to save in the querystring, right? so that piece of query string gets appended in each and every link that performns some kind of action...
I'm not sure, what are the advantages and disadvantages of using the querystring instead of hidden inputs???
I use different strategies depending on the character of the actual data. Things that are preferences, like default page size, I keep in a Preferences object (table) that is associated with the current logged in user and retrieve from there when needed.
Persistent settings associated with the current logon, like filter settings for a page, are stored in the user's session. Generally these are things that if a user sets them in the current session they should remain sticky. I think filter settings and visibility are like this. If I filter a list, navigate away from it to drill down into a particular item, then come back to the list, I want my filter settings to be reapplied -- so I make it part of the session.
Context-dependent settings -- like the current sort column or page number, are controlled using query parameters. Paging and sort controls (links) are built with the appropriate query parameters to "do the right thing" when clicked and pass any necessary query parameters to maintain or update the current context of the control. Using the query parameters allows you to use an HTTP GET, which is bookmarkable, rather than a POST. Using hidden form parameters makes it much harder for the user to save or enter a URL that takes them directly where they want to go. This is probably more useful for sorting than it is for paging, but the principle applies equally.

Resources