[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.dotnet.framework.aspnet.mobile

RE: Persisting properties across posts?

(Joseph Croney (MSFT))

4/2/2002 9:54:00 AM

4 Answers

Durk van Veen

4/2/2002 11:18:00 AM

0

There are actually some problems with that solution in the specific case
that I was trying to solve. I'm working on a problem that has been talked
about in this newsgroup a number of times already: how to get a separate
custom softkey label for each item in a list control (so not a non-default
label for the _entire_ control, but a separate customizable label for each
item in the list).

So basically, the MyProperty is actually the new property SoftKeyLabel which
I've added to a new class called MyMobileListItem, inheriting from
MobileListItem. I've created a MyListControlBuilder overriding
GetChildControlType so that it uses my item class, instead of the default
one that comes with the List control. I've also created a MyWmlListAdapter
which has a slightly tweaked call string to the RenderLink method so it
writes out the correct "title" attribute for the "option" tag.

Anyway, so far so good. I've gotten all this to work for the most part
(after making the requisite changes to web.config for the adapter which had
been alluded to in previous thread int his group) with some minor and some
major gotchas. One of the minor problems is that I cannot store my new
SoftKeyLabel property by simply using the ViewState for some reason,
probably because it is a "sub-control" of the List and managed by
MobileListItemCollection. While this is not a huge issue since I want to
basically just set the property at runtime anyway, I'd really like to figure
out how I can make my property behave like the Text and Value properties
that are already on the base class MobileListItem. These properties never
seem to lose their state. So, that is basically what I was trying to
accomplish when I posted the original message. If you have any additional
ideas based on this new info I'd be very interested.

I'm starting to fear that it will involve creating my own versions of List,
MobileListItem and MobileListItemCollection that do not inherit from the
base classes provided in System.Web.Mobile.DLL. I've messed with an
implementation of IStateManager on my inherited list item class, but while
IsTrackingViewState() and TrackViewState() get called, if I place
breakpoints in LoadViewState() and SaveViewState() the code never breaks...

My other problem so far, which is actually a lot more major as far as the
extent to which this is causing me stomach acid right now, is the fact that
the adapter code currently freaks out when I create a list that is long
enough to where it requires pagination. While the original page that comes
up first renders great, the second page (after you hit Next) causes some
kind of exception. I haven't had a chance to look at this in detail, but I
will probably know more later today. First: bed-time...

Durk

"Joseph Croney (MSFT)" <jcroney@microsoft.com> wrote in message
news:DSPTqth2BHA.2312@cpmsftngxa08...
> Hi Durk
> You can store the value of the property in the application view state.
> Here is a code example:
>
> public string MyProperty
> {
> get
> {
> String s = (String)ViewState["MyProperty"];
> return s != null ? s : String.Empty;
> }
> set
> {
> ViewState["MyProperty"] = value;
> }
> }
>
>
> Thanks,
> Joseph Croney
>
>
> -------------------------
> This posting is provided "AS IS" with no warranties, and confers no
rights.
> You assume all risk for your use. © 2002 Microsoft Corporation. All rights
> reserved.


Durk van Veen

4/3/2002 9:24:00 AM

0

To continue my previous post. I've had a chance to look into the problems
with overriding the MobileListItem a bit more. As I mentioned before, I have
basically two problems:
- the SoftKeyLabel property on my inherited myMobileListItem does not
survive post-back
- pagination with myMobileListItem does not work

My research highlights some basic problems with the current MMIT
implementation, in that it is really hard to inherit implementation from the
Microsoft-provided base controls:

The first problem seems to stem from the way that MobileListItemCollection
handles saving of the ViewState. This is what I found out with ILDASM. When
MobileListItemCollection::IStateManager::SaveViewState() is called, the
collection class will loop through all the items that it manages and query
the "Dirty" property. This property is a "hidden feature" of the
MobileListItem class (it's marked "assembly", a.k.a "internal" meaning
nothing outside System.Web.Mobile.DLL can call it). The "Dirty" property of
course only looks at the values of the Text and Value properties to
determine whether the item in question should be saved. Therefore no items
are saved to the ViewState if my custom SoftKeyLabel property changes if the
Text or Value don't change at the same time.

I can't override the Dirty property since it is marked "internal". I could
provide a "new" implementation for it, but then I'd have no way to call the
original implementation, which means that the Text and Value are no longer
saved properly. Alternatively my "Dirty" could always return true, which
would cause every single item to be saved to the view state. This has
obvious implications for the amount of useless state information that would
end up being saved to the view state.

The second problem is more serious for me right now because it renders my
inherited control completely useless: When you enable Pagination and pop
about 10 items in the inherited list, everything works fine for the first
page. However, on the second page, when the control re-instantiates the list
items, it uses MobileListItem objects instead of myMobileListItem. For some
reason the inherited "myListControlBuilder" is not used to determine what
type the children should be. So now my list has MobileListItems instead of
myMobileListItems which causes my adapter to throw an exception when it
attempts to examine the now non-existant SoftKeyLabel property.

From what I can tell right now, to get this to work I need to at least
provide my own implementation of List, ListControlBuilder, MobileListItem
and MobileListItemCollection.

Unfortunately because MobileListItemCollection internally uses classes that
are completely "internal", I'd also have to redefine ListDataHelper (an
undocumented class from System.Web.Mobile.DLL), DataSourceHelper (another
undocumented class) and IListControl (an internal interface).

This is turning into a heaping pile of code you'd have to write just to get
one simple property to behave correctly. It looks like there are some
serious issues with the useability of MMIT in it's current state as it
pertains to building your own stuff if you need to go a little beyond the
trivial stuff that is in the documentation.

I'm also worried that once you start writing custom implementations of all
these classes, there will eventually be problems because classes that are
all expected to share certain base classes, no longer do. For instance, if I
were to define an IMyListControl interface to replace IListControl, any
Microsoft code that scans a Form for objects implementing IListControl would
miss my own controls since they have IMyListControl instead.

Durk


(Simon Calvert)

4/3/2002 11:35:00 PM

0

Durk van Veen

4/4/2002 4:22:00 AM

0

Thanks for the info but I finally fixed this today by providing an new
implementation of MobileListItem, MobileListItemCollection and List, from
the System.Web.UI.WebControls namespace. I've never played with the kind of
inlining that you are doing in the suggested fix, but I'll give it a try
tomorrow, to see how it responds to my major problem situations: persisting
the custom property across post-backs, and across pages generated by the
pager functionality in Mobile Controls when there too many list items.

Something else that I tried today before I got it working was using the
IAttributeAccessor implemented on MobileListItem to add the value of
SoftKeyLabel programmatically:

((IAttributeAccessor)item).SetAttribute("SoftKeyLabel", val);

but properties set that way do not survive postbacks, I guess since they are
not put in the state bag for the control. The way I ended up implementing
uses entirely too much duplicated code (essentially reverse-engineered
Microsoft code) for my taste but it works at least. What I would really like
is for the next installment of System.Web.Mobile.DLL to not have quite as
many properties and classes marked "internal" so it is easier to do these
things by extending existing classes.

Specifically if the "Dirty" property on MobileListItem had been "protected"
instead of "internal", it would have made my live a whole lot easier.

Durk

"Simon Calvert" <simoncalonline@microsoft.com> wrote in message
news:crZw$c12BHA.396@cpmsftngxa07...
> This really may not fit your scenario, but did you consider using a
> templated list, where the ItemTemplate contains a <mobile:list or a
> <mobile:command (then add the OnItemCommand to the list to capture the
> bubbled event) that you databind to your dataitems? You could set the
> softkeylabel property to say another field in your datasource..
>
> <mobile: list OnItemCommand="Command_EventHandler" ...>
> <deviceSpecific>
> <Choice filter=....>
> <ItemTemplate>
> <mobile:command
> softkeylabel='<%#
> DataBinder.Eval(((MobileListItem)Container).DataItem, "field") %>'
> Text='<%#
> DataBinder.Eval(((MobileListItem)Container).DataItem, "field") %>'
> runat=server
> format="link"
> id="command"/>
> </ItemTemplate>
> </Choice>
>
> Simon Calvert
> This posting is provided "AS IS" with no warranties, and confers no
rights.
> You assume all risk for your use. © 2002 Microsoft Corporation. All rights
> reserved.
> ..