?
Solved

Page.Load event fired before RowCommand or OnClick command cause me a problem with a Formview Default Mode

Posted on 2006-06-03
5
Medium Priority
?
1,339 Views
Last Modified: 2008-01-09
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.DefaultMode = FormViewMode.Insert
            CType(fvTelephoneInfos.FindControl("EquipmentTypeLabel"), 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.SelectedValue
            Case "Telephone"
                WucTelephoneDetails1.DefaultDisplayMode = "Insert"
                WucTelephoneDetails1.Visible = 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

0
Comment
Question by:SergeGregoire
  • 2
4 Comments
 
LVL 14

Expert Comment

by:existenz2
ID: 16825258
It is not a problem. It is the way how ASP.NET works. Page_Load always get fired, also on postbacks. To prevent code from being executed which is in the Page_Load use this code:

If Not IsPostBack Then
    // code gets executed only when page gets loaded for the first time
End If
0
 
LVL 14

Expert Comment

by:existenz2
ID: 16825259
Hope I made the VB.NET code correct :P
0
 
LVL 1

Author Comment

by:SergeGregoire
ID: 16826730
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.DefaultMode = FormViewMode.Insert
        End If
    End Sub

Thanks anyway for your help existenz2, but your comment did not help me to fix my problem.
0
 
LVL 1

Accepted Solution

by:
DarthMod earned 0 total points
ID: 17174943
PAQed with points refunded (250)

DarthMod
Community Support Moderator
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Integration Management Part 2
Suggested Courses

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question