This is a migrated thread and some comments may be shown as answers.

early Load event firing of controls inside page view

7 Answers 608 Views
PageView
This is a migrated thread and some comments may be shown as answers.
Sadrul
Top achievements
Rank 2
Sadrul asked on 04 Oct 2010, 10:47 AM
i have custom controls inside a page view control. the custom control binds data on the load event. the problem is whenever a control is being added to the page view the load event of the control is being fired immediately inside the constructor of the control which holds the page view control. as a result it throws exception when trying to access data.

the following code is the component initialization code which is called from the constructor of the control which holds the page view control

private void InitializeComponent()
        {
            this.rdpvAppCodeFiles = new Telerik.WinControls.UI.RadPageView();
            this.rdpvpBank = new Telerik.WinControls.UI.RadPageViewPage();
            this.ctlManageBank1 = new CRS.Client.App.Documents.CodeFiles.ApplicationCodeFiles.BankDocuments.ctlManageBank();
            ((System.ComponentModel.ISupportInitialize)(this.rdpvAppCodeFiles)).BeginInit();
            this.rdpvAppCodeFiles.SuspendLayout();
            this.rdpvpBank.SuspendLayout();
            this.SuspendLayout();
            //
            // rdpvAppCodeFiles
            //
            this.rdpvAppCodeFiles.Controls.Add(this.rdpvpBank);
            this.rdpvAppCodeFiles.Dock = System.Windows.Forms.DockStyle.Fill;
            this.rdpvAppCodeFiles.Location = new System.Drawing.Point(0, 0);
            this.rdpvAppCodeFiles.Name = "rdpvAppCodeFiles";
            this.rdpvAppCodeFiles.SelectedPage = this.rdpvpBank;
            this.rdpvAppCodeFiles.Size = new System.Drawing.Size(846, 502);
            this.rdpvAppCodeFiles.TabIndex = 1;
            this.rdpvAppCodeFiles.Text = "radPageView1";
            this.rdpvAppCodeFiles.SelectedPageChanged += new System.EventHandler(this.rdpvAppCodeFiles_SelectedPageChanged);
            ((Telerik.WinControls.UI.RadPageViewStripElement)(this.rdpvAppCodeFiles.GetChildAt(0))).StripAlignment = Telerik.WinControls.UI.StripViewAlignment.Right;
            ((Telerik.WinControls.UI.RadPageViewStripElement)(this.rdpvAppCodeFiles.GetChildAt(0))).ItemContentOrientation = Telerik.WinControls.UI.PageViewContentOrientation.Horizontal;
            //
            // rdpvpBank
            //
            this.rdpvpBank.Controls.Add(this.ctlManageBank1);
            this.rdpvpBank.Location = new System.Drawing.Point(10, 10);
            this.rdpvpBank.Name = "rdpvpBank";
            this.rdpvpBank.Size = new System.Drawing.Size(750, 481);
            this.rdpvpBank.Text = "Bank";
            //
            // ctlManageBank1
            //
            this.ctlManageBank1.CurrentMode = CRS.Client.Automation.Documents.ctlDocumentUIBase.OperationMode.None;
            this.ctlManageBank1.Dock = System.Windows.Forms.DockStyle.Fill;
            this.ctlManageBank1.Document = null;
            this.ctlManageBank1.Location = new System.Drawing.Point(0, 0);
            this.ctlManageBank1.Name = "ctlManageBank1";
            this.ctlManageBank1.Size = new System.Drawing.Size(750, 481);
            this.ctlManageBank1.TabIndex = 0;
 
            // ctlApplicationCodeFilesSwitchBoard
            //
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.Controls.Add(this.rdpvAppCodeFiles);
            this.Name = "ctlApplicationCodeFilesSwitchBoard";
            this.Size = new System.Drawing.Size(846, 502);
            ((System.ComponentModel.ISupportInitialize)(this.rdpvAppCodeFiles)).EndInit();
            this.rdpvAppCodeFiles.ResumeLayout(false);
            this.rdpvpBank.ResumeLayout(false);
 
            this.ResumeLayout(false);
 
        }


here ctlManageBank1 is my custom control which loads data on its load event. the load event is being called immediately after the control is added to the page object of page view control (bold line).

if i use a tab control instead of a page view control everything goes fine. the load event fires at the time of showing the control, not inside the constructor.


7 Answers, 1 is accepted

Sort by
0
Emanuel Varga
Top achievements
Rank 1
answered on 04 Oct 2010, 02:36 PM
Hello Danilo,

With controls, there should be a different behavior defined than the standard forms, mostly because neither the Control, or RadControl has the Load event.

If you want some action to fire when the form has finished initializing, i would suggest moving the calls you are making in the constructor to a InitializeData public method, which you could safely call from the main Form.Load method, this way would be the safest way to handle this.

One other reason for this is the fact that controls have to Show up in the designer, and the constructor will be called there also, so my advice would be to create a method that will handle the control initialization (get, send data whatever you like)

Hope this helps, if you have any other questions or comments, please let me know,

Best Regards,
Emanuel Varga
0
Sadrul
Top achievements
Rank 2
answered on 05 Oct 2010, 09:28 AM
Hi Emanuel

thanks for the help. i think i haven't made myself clear.

i am using a custom User Control which has a load event. the custom user control is placed inside a RadPageView control. as you can see the designer generated code where the custom user control (ctlManageBank1) is being added to the RadPageView control collection (bold line). the load event of the custom user control is fired immediately after adding the control to the collection, which should not be the case. the load event should be fired when the control is shown to the user. the early firing of the load event is causing the problem. my data model is not initialized until the control is created. so i get a NullValueException inside the load event of the custom user control. i have checked for DesignMode so i don't get this exception in the designer. when i run the project i get the exception.
0
Emanuel Varga
Top achievements
Rank 1
answered on 05 Oct 2010, 09:44 AM
Hello Danilo,

If you are using Telerik controls and you want full theme support you will be inheriting controls from RadControl, and RadControl's base class does not have a Load event, that's why I suggested to change all of the logic from the UserControls Load to a public method you can call from Form.Load.

Hope this helps, if you have any other questions or comments, please let me know,

Best Regards,
Emanuel Varga
0
Julian Benkov
Telerik team
answered on 07 Oct 2010, 08:16 PM
Hello Danilo,

If RadPageView does not have pages and you add a page to it, the Load event of the UserControl is normally fired, because the page in gets selected. This is a normal and expected behavior and you will get the same experience with the standard Microsoft TabControl. If you add your UserControl to a page which is not initially selected, however, the Load event will not be fired. It will be fired when you select the page.

Emanuel, thank you for your comments on this topic.

Kind regards,

Julian Benkov
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Sadrul
Top achievements
Rank 2
answered on 08 Oct 2010, 07:54 AM
Hello Julian,

thanks for clarifying. that solves my problem.

thanks Emanuel for trying to help.

Regards
Danilo
0
Rudá Cunha
Top achievements
Rank 2
answered on 29 Jul 2011, 08:49 PM
I was using version Q1 2011 without problems. At the moment I update to thestart of Q2 error.

I have a form and have a form RadPageView, I have three pages (RadPageViewPage). And within each page I have a UserControl.

What happened before:

Form form = new Form();
Form (constructor);
Form (InitializeComponent);
UserControl (constructor);
form.ShowDialog();
Form (load);
UserControl (load);

This in Q1! Once upgraded to Q2:

Form form = new Form ();
Form (constructor);
Form (InitializeComponent);
UserControl (constructor);
UserControl (load) / / here comes the crash
form.ShowDialog ();
Form (load);

So I think it's not because the page is selected but there was a problem thatwas solved, then we now have the same problem!

I had to go back to Q1!
0
Julian Benkov
Telerik team
answered on 03 Aug 2011, 12:13 PM
Hi Rudá Cunha,

This is a normal and expected behavior and you will get the same experience with the standard Microsoft TabControl. If you add your UserControl to a page which is not initially selected, however, the Load event will not be fired. It will be fired when you select the page.

Please view the example in attached screenshots. If we add the UserControl to radPageViewPage3 that is not initialy selected the Load event not fired for UserControl. When the UserControl was added to radPageViewPage1, which is active selected page, then the UserControl event is fired.

Best wishes,
Julian Benkov
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get now >>

Tags
PageView
Asked by
Sadrul
Top achievements
Rank 2
Answers by
Emanuel Varga
Top achievements
Rank 1
Sadrul
Top achievements
Rank 2
Julian Benkov
Telerik team
Rudá Cunha
Top achievements
Rank 2
Share this question
or