473,659 Members | 2,632 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 6903
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 EditItemTemplat e
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
ReadOnlyDataSou rce--an internal and undocumented class. Comparing to
SqlDataSourceVi ew or ObjectDataSourc eView, 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.W ebControls. BindableTemplat eBuilder 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 EditItemTemplat e
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
ReadOnlyDataSou rce--an internal and undocumented class. Comparing to
SqlDataSourceVi ew or ObjectDataSourc eView, 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
1265
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 = (Me.FormView1.lengthTextBox.text * 2) this shows an error of couse, what is the new correct way to do this using MS formview data control?
2
4261
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 for the repost. I'd like to make use of the asp:Wizard control to present a step-by-step guided experience for my user to fill out a complicated data-entry form. I'd like to make use of two-way databinding provided by the asp:FormView control...
6
2066
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 the data from the fields to which they are bound; yet they will return null values when the 'Update' LinkButton is clicked. The responder thought this might have something to do with naming containers. If so, this is similar to an issue in...
2
8739
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 description (i.e. a colors table, so there is a colors ID and a color description). The data source the FormView is pulling data from stores (in this example) the primary key for the colors table. My ultimate goal is when the FormView goes into...
7
4340
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 sqldatasource of the formview. If i put this textboxes outside the table everything works well, but as soon as i put them inside the table (in order to organize the layout in the right way) they doesn't work. They works only as eval() and not bind()...
3
3154
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 Bind() can only be used in the context of a databound control. Any help with this would be appreciated. -- Thanks in advance,
2
9889
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 longer but this should illustrate the problem: <asp:FormView ID="bookFormView" runat="server" DataSourceID="bookSqlDataSource"> <ItemTemplate> <asp:textBox id="name" text='<%# Eval("name") %>'
4
4679
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 in the ItemCommand event but I can't redirect from here because the ItemUpdated event hasn't fired yet. I can put a variable in the code-behind class which is gets the
1
10256
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 parameter. The control is in the edit template of the FormView, which is not visible from the view template. I'm able to change properties of controls on the view template. However, when trying to set them on the edit template the control...
0
8851
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8751
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8539
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6181
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5650
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4176
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4342
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2759
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1739
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.