PanelBar and ItemTemplates

4 posts, 0 answers
  1. lchesnais
    lchesnais avatar
    39 posts
    Member since:
    Feb 2007

    Posted 10 Apr 2008 Link to this post

    Hello,

    I've got a RadDatePicker (ID=rdpDate) in the ItemTemplate of a RadPanelItem (see code below).
    Does some know how I can access rdpDate from the code behind or how can I figure out its ClientID to be able to $find() it in Javascript?

    Thanks in advance.

    BR, Laurent

    <telerik:RadPanelBar  
            runat="server" 
            ID="RPB1" 
            Skin="Office2007" 
            Width="100%" 
            Height="100%" 
            ExpandMode="FullExpandedItem" 
            > 
        <Items> 
            <telerik:RadPanelItem Text="Specific date">  
                <Items> 
                    <telerik:RadPanelItem> 
                        <ItemTemplate> 
                            <div class="panelMainDiv">  
                                <telerik:RadDatePicker  
                                        runat="server" 
                                        id="rdpDate" 
                                        > 
                                </telerik:RadDatePicker> 
                                <br /> 
                                <span>Only transactions whose date is equal to this specific date will be displayed.</span> 
                            </div> 
                        </ItemTemplate> 
                    </telerik:RadPanelItem> 
                </Items> 
            </telerik:RadPanelItem> 
        </Items> 
    </telerik:RadPanelBar> 
     

  2. lchesnais
    lchesnais avatar
    39 posts
    Member since:
    Feb 2007

    Posted 11 Apr 2008 Link to this post

    Hello,

    Thanks to Seth's post (about another subject), I found my solution:
    I had to add a Value property to the RadPanelItem (in my case <telerik:RadPanelItem Value="rpiDate">, see below).
    Then I use the following code:

    * In the code-behind (C#)
    RBP1.FindItemByValue("rpiDate").FindControl("rdpDate")  
     
    * In JS:
    function testFunction()  
    {  
      var clientID = "<%= RPB1.FindItemByValue("rpiDate").FindControl("rdpDate").ClientID %>" 
      var rdpDate = $find(clientID);  
    }  
     

    If someone has a better solution, please let me know.

    BR, Laurent

    <telerik:RadPanelBar     
            runat="server"    
            ID="RPB1"    
            Skin="Office2007"    
            Width="100%"    
            Height="100%"    
            ExpandMode="FullExpandedItem"    
            >    
        <Items>    
            <telerik:RadPanelItem Text="Specific date">     
                <Items>    
                    <telerik:RadPanelItem Value="rpiDate">    
                        <ItemTemplate>    
                            <div class="panelMainDiv">     
                                <telerik:RadDatePicker     
                                        runat="server"    
                                        id="rdpDate"    
                                        >    
                                </telerik:RadDatePicker>    
                                <br />    
                                <span>Only transactions whose date is equal to this specific date will be displayed.</span>    
                            </div>    
                        </ItemTemplate>    
                    </telerik:RadPanelItem>    
                </Items>    
            </telerik:RadPanelItem>    
        </Items>    
    </telerik:RadPanelBar>    
     
  3. Daron
    Daron avatar
    80 posts
    Member since:
    Dec 2007

    Posted 18 Apr 2008 Link to this post

    Thanks for the post Laurent! Saved me a lot of hair-pulling.
    Following on from that, and to neaten things up, I use this code to achieve the same effect:

    1 private MyCustomControl _myCustomControl = null
    2 protected MyCustomControl MyCustomControl1 
    3
    4  get 
    5  { 
    6  if (_myCustomControl == null
    7  _myCustomControl = (MyCustomControl)RadPanelBar1.FindItemByValue("RadPanelItem1").FindControl("MyCustomControl1"); 
    8  return _myCustomControl; 
    9  } 
    10


    The advantage of this approach is that if Telerik manage to find a way to expose the embedded controls (so you don't have to use "FindControl") you can just deleted the method and your code will pick up the control from the generated code signature!

    Cheers,
    DT
  4. lchesnais
    lchesnais avatar
    39 posts
    Member since:
    Feb 2007

    Posted 22 Apr 2008 Link to this post

    Hello Daron,

    You are welcome.

    I like your code. Using such properties might help keeping a clean code.
    However, I don't think Telerik will ever be able to expose the embedded controls because of the way ASP.NET manages controls within containers: two controls may have the same ID as long as they are within two different containers.

    BR, Laurent
Back to Top