473,408 Members | 2,405 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

Limitation of FormView Control?

It appears that FormView controls require the >>exact<< same layout of controls and control types in the various templates in order
to function properly. Failure to do so results in a "failure to load ViewState" exception when a mode change occurs.

Is this correct?

If so, it would appear to defeat the >>entire point<< of being able to use customized templates for the various modes.

Assuming this limitation exists, what's the workaround? For example, in my current application, I have various lookup fields that
can only take on certain values. I want those to display as Labels in ReadOnly mode, and as DropDownLists in Edit and Insert mode.
Do I have to override the LoadViewState method for the page and map the control values back and forth? Or just jettison ViewState
for the FormView and rebind the control on every postback?

As an aside, I did not see any mention of this limitation in the docs. It should have been mentioned in screaming dayglo orange 18
point type.

- Mark
Feb 13 '07 #1
5 6891
Hi again Mark,

No because each template is independent so viewstates for different
templates do not interfere with each other.

--
Milosz
"Mark Olbert" wrote:
It appears that FormView controls require the >>exact<< same layout of controls and control types in the various templates in order
to function properly. Failure to do so results in a "failure to load ViewState" exception when a mode change occurs.

Is this correct?

If so, it would appear to defeat the >>entire point<< of being able to use customized templates for the various modes.

Assuming this limitation exists, what's the workaround? For example, in my current application, I have various lookup fields that
can only take on certain values. I want those to display as Labels in ReadOnly mode, and as DropDownLists in Edit and Insert mode.
Do I have to override the LoadViewState method for the page and map the control values back and forth? Or just jettison ViewState
for the FormView and rebind the control on every postback?

As an aside, I did not see any mention of this limitation in the docs. It should have been mentioned in screaming dayglo orange 18
point type.

- Mark
Feb 14 '07 #2
Milosz,

The workaround I'm using is to turn off ViewState for the FormView
control, and then rebind it on every postback. Since the FormView
never tries to load its state from ViewState the problem of the
controls and control layout being different doesn't arise.
Fortunately, the overhead associated with databinding the FormView in
my application is pretty low.

But it still seems like a kludgy or incomplete solution/approach.
After thinking about it a bit, I got to wondering why the FormView
doesn't support a set of "mapping" properties that indicate which
controls relate to controls in other templates, e.g.,

<FieldMap>
<MapEntry ReadOnlyControl="a" EditControl="b" InsertControl="c" /
>
....
</FieldMap>

Granted, validating the configuration information would be a bit of a
bear, but that's what software developers are for :).

On a related subject, do you happen to know why using "old style"
databinding (i.e., assigning a source to DataSource and calling
DataBind(), as opposed to using DataSourceID) is a second-class
citizen when it comes to retrieving field values in the event
handlers? Given that the bindings are set up by calls to Bind() it
seems to me the FormView "knows" which control relates to which
database fields, regardless of whether new style or old style
databinding is being used. As a user of the "old style" it's a pain in
the butt to have to manually extract the field values in the event
handlers (FYI, I use the old approach because I tend to like to be
able to control when and where databinding takes place; the new style,
from what I can see, has databinding take place whenever the page
"wants" to databind, and I'd have to cancel the databinding in
situations where I don't want it done).

- Mark

Feb 14 '07 #3
Hi Mark,

From the symptom of the issue you described, it's similar to one of known
issue of FormView when following conditions are met:

1) Uses different controls or different order in FormView's ItemTemplate
and EditItemTemplate
2) Hide the FormView in its ItemUpdated event

The workaround to this is to set DefaultMode of FormView to Edit. Let me
know whether or not this is the case.

In ASP.NET 2.0, although we offered two different ways of binding:
DataSource vs. DataSourceID, under the hood of data-bound controls data
retrieval occurs in just one way--through data source view objects. If the
control is bound to a data source control, the incorporated data source
view object is retrieved via the members of the IDataSource interface. If
the control is bound to an enumerable object, a data source view object is
dynamically built. If the DataSource is non-empty, the bound object is
wrapped in a dynamically created data source view object of type
ReadOnlyDataSource--an internal and undocumented class. Comparing to
SqlDataSourceView or ObjectDataSourceView, this readonly data source view
object is rather limited.

Hope this helps.

Regards,
Walter Wang (wa****@online.microsoft.com, remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.

Feb 14 '07 #4
Hi Mark,

In addition to Walter’s reply, if you are curious what actually happens
under the mask, get yourself a good disassembler (i.e. Reflector that is
available for free at this address http://www.aisto.com/roeder/dotnet/) a
have a look at System.Web.UI.WebControls. BindableTemplateBuilder class.

Regards

Milosz

--
Milosz
"Walter Wang [MSFT]" wrote:
Hi Mark,

From the symptom of the issue you described, it's similar to one of known
issue of FormView when following conditions are met:

1) Uses different controls or different order in FormView's ItemTemplate
and EditItemTemplate
2) Hide the FormView in its ItemUpdated event

The workaround to this is to set DefaultMode of FormView to Edit. Let me
know whether or not this is the case.

In ASP.NET 2.0, although we offered two different ways of binding:
DataSource vs. DataSourceID, under the hood of data-bound controls data
retrieval occurs in just one way--through data source view objects. If the
control is bound to a data source control, the incorporated data source
view object is retrieved via the members of the IDataSource interface. If
the control is bound to an enumerable object, a data source view object is
dynamically built. If the DataSource is non-empty, the bound object is
wrapped in a dynamically created data source view object of type
ReadOnlyDataSource--an internal and undocumented class. Comparing to
SqlDataSourceView or ObjectDataSourceView, this readonly data source view
object is rather limited.

Hope this helps.

Regards,
Walter Wang (wa****@online.microsoft.com, remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.

Feb 14 '07 #5
"ma**@arcabama.com" wrote:
<snip>
>
On a related subject, do you happen to know why using "old style"
databinding (i.e., assigning a source to DataSource and calling
DataBind(), as opposed to using DataSourceID) is a second-class
citizen when it comes to retrieving field values in the event
handlers?
<snip>

In my opinion, I think the DataBound controls in 2.0 just give you a
low-cost alternative for quickly creating RAD style apps/prototypes. I don't
think they are meant for all cases. In situations where the default
behaviors of the DataBound controls are adequate, they are a good choice
(kind of like MS's answer to scaffolds in Ruby).

In cases where you need to really control how your binding works, I think
you'll spend more time kludging around with DataBound control (FormView),
than it would take to create your own out of a MultiView. Personally, I'd
use DataBound controls for read-only data (GridViews), FormViews for low-cost
apps/prototypes where you have control over the requirements, and manual
binding for most other cases.

I'm curious what people are doing,
Jason Vermillion
Feb 14 '07 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: TdarTdar | last post by:
I wanted to add three columns up on the form and run some logic to fill in the third but not sure how to call the field names in the formview control. Dim Girth As Integer Elenght =...
2
by: John R. Lewis | last post by:
I posted this yesterday with a different email address. I am reposting with my fake-address as given to me by Microsoft so that I can be guraranteed a response from a support representative. Sorry...
6
by: Douglas J. Badin | last post by:
Earlier this month, there was a posting about this without a definitive answer. If you place a Wizard inside a FormView's EditItemTemplate the bound fields contained within the View will display...
2
by: P. Yanzick | last post by:
Hello, I am creating an edit template for a FormView control, changing one of the textboxes to a dropdown box. The dropdown will be populated from a simple table with the primary key, and a...
7
by: Lorenzino | last post by:
Hi, I have a problem with bindings in a formview. I have a formview; in the insert template i've created a wizard control and inside it i have an HTML table with some textboxes bound to the...
3
by: sck10 | last post by:
Hello, I am trying to bind an arraylist to a FormView DropDownList control in the PreRender state. The error that I get is the following: Databinding methods such as Eval(), XPath(), and...
2
by: Ned Balzer | last post by:
I'm trying to create a formview bound to a sqldatasource, and use a stored procedure to insert data from the formview into several tables. I have some simplified code below, the real code is much...
4
by: J055 | last post by:
Hi I have 2 update buttons in my FormView ('Apply' and 'OK'). I want both buttons to update the data source but the 'OK' button should redirect afterwards. I can see which button is clicked...
1
by: SteveT | last post by:
Before I pull out what little hair I have left, I'm swallowing my pride and asking the Oracles of .Net: I'm trying to set a property in a dropdown list control in a FormView, based on a session...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.