FormView Insert

J

J055

Hi

How do I keep the values of the controls in a FormView after a PostBack in
Insert mode?

Thanks
Andrew
 
W

Walter Wang [MSFT]

Hi Andrew,

Do you mean that after insert, you keep the FormView in insert mode and you
want to retain the control values in the fields?

So far I haven't found a built-in property or method to do that, it seems
the InsertItemTemplate gets reloaded and the controls inside it will get
reset. I'll do more research and get back to you. In the meanwhile, please
let me know if I've misunderstood your question.


Sincerely,
Walter Wang ([email protected], remove 'online.')
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications. If you are using Outlook Express, please make sure you clear the
check box "Tools/Options/Read: Get 300 headers at a time" to see your reply
promptly.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================

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

J055

Hi Walter

Thanks for the response. I've realized that the FormView will only keep the
values if the Page.IsValid = false so I 've got round the problem by using a
customvalidator and rewritting some business logic which handles the insert.

This works for me now.

Thanks
Andrew
 
W

Walter Wang [MSFT]

Hi Andrew,

Sorry for late reply. I was consulting this question recently.

First, the problem appears to be that the FormView is told by the data
source control that the data has changed, and therefore it should rebind to
get the new data. This actually should not have been done since we're still
in Insert mode. I have got a workaround for your reference: Inherit from
FormView to create your own FormView control, override
OnDataSourceViewChanged and set RequiresDataBinding to false if we're in
Insert mode:

public class MyFormView : FormView
{
protected override void OnDataSourceViewChanged(object sender,
EventArgs e)
{
if (this.CurrentMode == FormViewMode.Insert)
{
this.RequiresDataBinding = false;
}
else
{
base.OnDataSourceViewChanged(sender, e);
}
}
}

I've tested it on my side and it seems working correctly. Please give it a
try and let me know the result.

By the way, I don't think making the page invalid is good idea to
workaround the issue here, :)


Regards,
Walter Wang ([email protected], 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.
 
A

adlahuk

Hi Walter,

Could you please redo the code as VB.Net. I'm not too hot with c# and
not sure how to convert it.

Will I have to remove my formview and replace with this inherited one
or use the same?

Thanks, Adam

'Walter Wang [MSFT said:
;7187455']Hi Andrew,

Sorry for late reply. I was consulting this question recently.

First, the problem appears to be that the FormView is told by the data
source control that the data has changed, and therefore it should
rebind to
get the new data. This actually should not have been done since we're
still
in Insert mode. I have got a workaround for your reference: Inherit
from
FormView to create your own FormView control, override
OnDataSourceViewChanged and set RequiresDataBinding to false if we're
in
Insert mode:

public class MyFormView : FormView
{
protected override void OnDataSourceViewChanged(object sender,
EventArgs e)
{
if (this.CurrentMode == FormViewMode.Insert)
{
this.RequiresDataBinding = false;
}
else
{
base.OnDataSourceViewChanged(sender, e);
}
}
}

I've tested it on my side and it seems working correctly. Please give
it a
try and let me know the result.

By the way, I don't think making the page invalid is good idea to
workaround the issue here, :)


Regards,
Walter Wang ([email protected], 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.
 
W

Walter Wang [MSFT]

Hi Adam,

No problem. Here's the code of MyFormView in VB.NET:

Public Class MyFormView
Inherits FormView

Protected Overrides Sub OnDataSourceViewChanged(ByVal sender As Object,
ByVal e As EventArgs)
If (MyBase.CurrentMode = FormViewMode.Insert) Then
MyBase.RequiresDataBinding = False
Else
MyBase.OnDataSourceViewChanged(sender, e)
End If
End Sub

End Class


Here's a tip on how to convert simple C# code to VB.NET using Reflector
(http://www.aisto.com/roeder/dotnet/):

1) Create a simple C# class library, add reference to System.Web, add
MyFormView.cs in my last reply. Build it.
2) Open the built assembly in Reflector, select disassemble language as
VB.NET and view the disassembled source code, you will see the VB.NET
version code of the MyFormView class. Don't forget to enable Reflector's
option: View/Options: Show PDB Symbols.


Hope this helps.

Regards,
Walter Wang ([email protected], 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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

Forum statistics

Threads
473,774
Messages
2,569,598
Members
45,152
Latest member
LorettaGur
Top