Can't change mode in FormView

  • Thread starter Thread starter staeri
  • Start date Start date
S

staeri

I have a FormView with DefaultMode="Insert".

I want to change this to DefaultMode="Edit" with code but this doesn't
work. It's still in insert mode. I've used the following code:

Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs)
FormView1.ChangeMode(FormViewMode.Edit)
FormView1.DefaultMode = FormViewMode.Edit
End Sub

What is wrong? If I change to DefaultMode="Edit" manually in the aspx
file it works but not with code.

Very grateful for fast help!

Regards,

S
 
When I change to the following code it works:

Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Me.Load
If (Not IsPostBack) Then
If Len(Request.QueryString("Mode")) > 0 Then
FormView1.ChangeMode(FormViewMode.Edit)
FormView1.DefaultMode = FormViewMode.Edit
End If
End If
End Sub

What does Handles Me.Load do?

Regards,

S
 
Handles Me.Load actually causes your Page_Load method to execute. That was
your problem earlier when you couldn't change values.
 
But I've user Page_Load in other situations before without the Me.Load
and everything has been executed then.

Should Me.Load always be used?
 
It may have something to do with the AutoEventWireup attribute in the @Page
directive. Since I'm a C# programmer, I'm not really sure, but I'll
research it and reply back (unless a VB guru can respond faster).
 

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

Back
Top