Stephan Bourgeois
asked on
Page.Load event fired before RowCommand or OnClick command cause me a problem with a Formview Default Mode
Hi experts,
I have a gridview control that is displaying a WebUserControl that is containing a FormView control to display or edit the details of the selected item.
I have also a button to insert a new record in the database.
I have created 2 public property to help me control the way to display the formview and when the data has been updated to refresh the GridView.
Public Event DataUpdated As EventHandler
Public DefaultDisplayMode As String
Protected Overridable Sub OnDataUpdated(ByVal e As EventArgs)
RaiseEvent DataUpdated(Me, e)
End Sub
The problem I have is with the DefaultDisplayMode.
When I click the button, I want to display the formview in Insert mode. So in the Page.Load of the WebUserControl, Iput the following code:
WUC Page.Load Sub:
If DefaultDisplayMode = "Insert" Then
fvTelephoneInfos.DefaultMo de = FormViewMode.Insert
CType(fvTelephoneInfos.Fin dControl(" EquipmentT ypeLabel") , Label).Text = "Telephone"
End If
OnClick Sub:
Protected Sub btnAddConfiguration_Click( ByVal sender As Object, ByVal e As System.EventArgs) Handles btnAddConfiguration.Click
' Dim strCommand As String
Dim strCustID As String
strCustID = Session("CustID")
Select Case ddlEquipmentType.SelectedV alue
Case "Telephone"
WucTelephoneDetails1.Defau ltDisplayM ode = "Insert"
WucTelephoneDetails1.Visib le = True
...
The problem, is that the WebUserControl Page.Load event is lunched before the Button OnClick event or Gridview RowCommand, so the DefaultDisplayMode is not yet initialized.
Is there a way to tels the WebUserControl that the DefaultDisplayMode property has changed, or processed the WebUserControl Page.Load event after the Onclick and RowCommand events.
Thanks
I have a gridview control that is displaying a WebUserControl that is containing a FormView control to display or edit the details of the selected item.
I have also a button to insert a new record in the database.
I have created 2 public property to help me control the way to display the formview and when the data has been updated to refresh the GridView.
Public Event DataUpdated As EventHandler
Public DefaultDisplayMode As String
Protected Overridable Sub OnDataUpdated(ByVal e As EventArgs)
RaiseEvent DataUpdated(Me, e)
End Sub
The problem I have is with the DefaultDisplayMode.
When I click the button, I want to display the formview in Insert mode. So in the Page.Load of the WebUserControl, Iput the following code:
WUC Page.Load Sub:
If DefaultDisplayMode = "Insert" Then
fvTelephoneInfos.DefaultMo
CType(fvTelephoneInfos.Fin
End If
OnClick Sub:
Protected Sub btnAddConfiguration_Click(
' Dim strCommand As String
Dim strCustID As String
strCustID = Session("CustID")
Select Case ddlEquipmentType.SelectedV
Case "Telephone"
WucTelephoneDetails1.Defau
WucTelephoneDetails1.Visib
...
The problem, is that the WebUserControl Page.Load event is lunched before the Button OnClick event or Gridview RowCommand, so the DefaultDisplayMode is not yet initialized.
Is there a way to tels the WebUserControl that the DefaultDisplayMode property has changed, or processed the WebUserControl Page.Load event after the Onclick and RowCommand events.
Thanks
Hope I made the VB.NET code correct :P
ASKER
I found a solution myself.
Since the Page.Load event is fired before the Gridview.RowCommand and Button.OnClick, I put my test condition in the Page_Prerender event.
Since the Prerender event is fire just before to display the page, the DefaultDisplayMode is set and the formview appear in the appropriate mode.
Protected Sub Page_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.PreRender
If DefaultDisplayMode = "Insert" Then
fvTelephoneInfos.DefaultMo de = FormViewMode.Insert
End If
End Sub
Thanks anyway for your help existenz2, but your comment did not help me to fix my problem.
Since the Page.Load event is fired before the Gridview.RowCommand and Button.OnClick, I put my test condition in the Page_Prerender event.
Since the Prerender event is fire just before to display the page, the DefaultDisplayMode is set and the formview appear in the appropriate mode.
Protected Sub Page_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.PreRender
If DefaultDisplayMode = "Insert" Then
fvTelephoneInfos.DefaultMo
End If
End Sub
Thanks anyway for your help existenz2, but your comment did not help me to fix my problem.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
If Not IsPostBack Then
// code gets executed only when page gets loaded for the first time
End If