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

PanelBar and ItemTemplates

3 Answers 136 Views
PanelBar
This is a migrated thread and some comments may be shown as answers.
lchesnais
Top achievements
Rank 1
lchesnais asked on 10 Apr 2008, 08:36 PM
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> 
 

3 Answers, 1 is accepted

Sort by
0
lchesnais
Top achievements
Rank 1
answered on 11 Apr 2008, 11:13 AM
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>    
 
0
Daron
Top achievements
Rank 1
answered on 18 Apr 2008, 04:19 PM
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:

private MyCustomControl _myCustomControl = null
protected MyCustomControl MyCustomControl1 
 get 
 { 
 if (_myCustomControl == null
 _myCustomControl = (MyCustomControl)RadPanelBar1.FindItemByValue("RadPanelItem1").FindControl("MyCustomControl1"); 
 return _myCustomControl; 
 } 


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
0
lchesnais
Top achievements
Rank 1
answered on 22 Apr 2008, 03:26 PM
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
Tags
PanelBar
Asked by
lchesnais
Top achievements
Rank 1
Answers by
lchesnais
Top achievements
Rank 1
Daron
Top achievements
Rank 1
Share this question
or