Custom control's overrides not being called

Last post 07-30-2009 2:22 AM by Allen Chen – MSFT. 5 replies.

Sort Posts:

  • Custom control's overrides not being called

    07-25-2009, 2:27 PM
    • Member
      point Member
    • rapha22.1
    • Member since 07-25-2009, 6:13 PM
    • Posts 3

    Hi!

    I have created a custom control and overrided the OnInit method, but it is never called. I've tried overriding other methods (like OnLoad and OnLoadViewState) and it doesn't work either. The custom control is inside a list property of a user control, and I add it to the user control at the aspx, like the following:

    <kcc:HierarchicalFilter runat="server" ID="kccFilterAttakc" FilterSummaryId="kccResumoAttack">
    	<FilterSteps>	
    		<kcc:HierarchicalFilterStep runat="server" Title="Attakc" Key="ATTAKC" TypeName="FIA.BusinessObjects.ClienteAttakc" SelectMethod="ListByUsuario" ListDataTextField="RAZAO_SOCIAL" ListDataValueField="COD_CLIENTE" UserDefaultParameters="true" >
    			<NextStep runat="server" Title="RCA" Key="RCA" TypeName="FIA.BusinessObjects.Rca" SelectMethod="List" ListDataTextField="NOME" ListDataValueField="COD_RCA" >
    				<Parameters>  
    					<kcc:HierarchicalFilterStepParameter runat="server" ParameterType="SelectedValues" />
    					<kcc:HierarchicalFilterStepParameter runat="server" ParameterType="Fixed" Value="ATTAKCS" Type="String" />			
    				</Parameters>
    			</NextStep>
    		</kcc:HierarchicalFilterStep>		
    	</FilterSteps>
    </kcc:HierarchicalFilter>

    Where HierarchicalFilter is the user control and HierarchicalFilterStep is the custom control (NextStep is a HierarchicalFilterStep too, and its overrided methods of Control are not called either).

    When I add the custom control by code at the user control ("this.Controls.Add(new HierarchicalFilterStep()") the methods are callewith no problems.


    Any ideas?


    Thanks in advance!

     
  • Re: Custom control's overrides not being called

    07-27-2009, 2:22 AM

    Hi,

    Could you share a demo that can reproduce this issue? You can upload the project to http://skydrive.live.com/ and paste the download link here for me to test.

    Sincerely,
    Allen Chen
    Microsoft Online Community Support

    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
  • Re: Custom control's overrides not being called

    07-27-2009, 11:50 AM
    • Member
      point Member
    • rapha22.1
    • Member since 07-25-2009, 6:13 PM
    • Posts 3

    Well, I've got the problem. My custom controls inside the User Control were not being added to the Controls property (like they were not controls). My question now is: why does it happened? Do I got to always add my custom controls manually to the container control? How can I tell the framework to do this for me?


    Thanks!

  • Re: Custom control's overrides not being called

    07-28-2009, 10:57 PM

    rapha22.1:

    Well, I've got the problem. My custom controls inside the User Control were not being added to the Controls property (like they were not controls). My question now is: why does it happened? Do I got to always add my custom controls manually to the container control? How can I tell the framework to do this for me?


    Thanks!

     

    Could you tell me how do you initialize the web user control? Please use this way to initialize it or else the controls defined in ascx will not be added:

    WebUserControl1 webusercontrol= (WebUserControl1) Page.LoadControl("WebUserControl1.ascx");

     

    Sincerely,
    Allen Chen
    Microsoft Online Community Support

    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
  • Re: Custom control's overrides not being called

    07-29-2009, 12:24 PM
    • Member
      point Member
    • rapha22.1
    • Member since 07-25-2009, 6:13 PM
    • Posts 3

    I use a <%@ Register %> tag on the page, like the following:


    <%@ Register TagPrefix="kcc" TagName="HierarchicalFilter" Src="~/UserControls/Filtros/HierarchicalFilter.ascx" %>


    I've never had to initialize any user control like that. What I want is that the developer who will user my User Control don't need to explicitly initialize it, just register it on the page and use! Is there any way to achieve this?

    Anyway, how does this kind o initialization works? Where should this line be? At the overrided OnInit on the page? Why does the framework don't initialize my controls when they're added via markup?

    Thanks, Allen, for your attention!

  • Re: Custom control's overrides not being called

    07-30-2009, 2:22 AM

    rapha22.1:

    I use a <%@ Register %> tag on the page, like the following:


    1. <%@ Register TagPrefix="kcc" TagName="HierarchicalFilter" Src="~/UserControls/Filtros/HierarchicalFilter.ascx" %>  


    I've never had to initialize any user control like that. What I want is that the developer who will user my User Control don't need to explicitly initialize it, just register it on the page and use! Is there any way to achieve this?

    Anyway, how does this kind o initialization works? Where should this line be? At the overrided OnInit on the page? Why does the framework don't initialize my controls when they're added via markup?

    Thanks, Allen, for your attention!

     

    It should work.. Could you provide a demo that can repro this issue?

    You can upload the project to http://skydrive.live.com/ and paste the download link here for me to test.

    Sincerely,
    Allen Chen
    Microsoft Online Community Support

    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Page 1 of 1 (6 items)