What those methods for?

This forum is only for questions or discussions about working with the mojoPortal source code in Visual Studio, obtaining the source code from the repository, developing custom features, etc. If your question is not along these lines this is not the right forum. Please try to post your question in the appropriate forum.

Please do not post questions about design, CSS, or skinning here. Use the Help With Skins Forum for those questions.

This forum is for discussing mojoPortal development

This forum is only for questions or discussions about working with the mojoPortal source code in Visual Studio, obtaining the source code from the repository, developing custom features, etc. If your question is not along these lines this is not the right forum. Please try to post your question in the appropriate forum.

You can monitor commits to the repository from this page. We also recommend developers to subscribe to email notifications in the developer forum as occasionally important things are announced.

Before posting questions here you might want to review the developer documentation.

Do not post questions about design, CSS, or skinning here. Use the Help With Skins Forum for those questions.
This thread is closed to new posts. You must sign in to post in the forums.
5/13/2010 4:37:08 PM
Gravatar
Total Posts 5

What those methods for?

Hi, I'm developing my own controls and some methods not clear for me.

I took for example code of CountryStateSetting.ascx (Web/Controls); I put in my control a DropDownList, which I am filling in the Page_Load and this method fires twice, so I'm getting double values in my dropdownlist.

There is an example of original CountryStateSetting.ascx

protected override void OnInit(EventArgs e)
{
base.OnInit(e);
this.Load += new EventHandler(Page_Load);
EnsureControls();
ddCountry.SelectedIndexChanged += new EventHandler(ddCountry_SelectedIndexChanged);
}

Why Joe add this EventHandler? this.Load += new EventHandler(Page_Load); When I comment this string, my DropDownList began populated correctly (one time).

And why Joe are using EnsureControls()  procedure? Why is that for?

5/14/2010 11:08:06 AM
Gravatar
Total Posts 18439

Re: What those methods for?

Hi Konstantin,

In your custom control in the .ascx file, make sure you have AutoEventWireup="false" if you are wiring up the event yourself and this is true then the event is wired twice so it fires twice.

My recollection is that I needed the EnsureControls because in Module Settings we are loading this control dynamically (ie it is not a control declared in the page). So in this case with a dynamically loaded control it must be re-created again on postback and this method prevented a possible null reference exception if the event sequence was different than the page event sequence due to the timing of when the control s created on postback.

Hope it helps,

Joe

5/14/2010 1:16:09 PM
Gravatar
Total Posts 5

Re: What those methods for?

Thanks, Joe!

Now it's working like it should :) I forgot to set AutoEventWireup to false

You must sign in to post in the forums. This thread is closed to new posts.