We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

How do I get a reference to a Control on the Toolbar

I have added a drop down calendar control to a toolbar using the TemplateItem (I'll post the HTML Markup at end of this message).  Basically I need to get a reference to the drop down calendar (ID="ddccDateSelection_") which is defined in the TollBarTemplateControl (ID="tbtcCSelectDate_") which is used by the TollBarItem (ID="tbiSelectDate_").  I need to be able to set the date in the control based on other actions take by the user on the page.
 
I've tried the "FindControl()" option but it always returns empty (Nothing).   If I use the debugger in Visual Studio I can use the existing reference to the toolbar itself and through the "Controls" property see the template, but I can't get to the actual drop down calendar control.
 
Here is the markup:
            <syncfusion:ToolBar ID="tbDailySchedule_" runat="server" AutoFormat="Office2007 Blue" Width="100%" OnClick="Toolbar_Click_" Locked="True">
               <Items>
                  <syncfusion:ToolBarItem ID="tbiDailySchedulePlus1Month_" Text="+1 Month" ToolTip="Increase the report date by one month" AppearanceMode="TextOnly" TextWrap="false" />
                  <syncfusion:ToolBarItem ID="tbiDailySchedulePlus1Week_" Text="+1 Week" ToolTip="Increase the report date by one week" AppearanceMode="TextOnly" TextWrap="false" />
                  <syncfusion:ToolBarItem ID="tbiDailySchedulePlus1Day_" Text="+1 Day" ToolTip="Increase the report date by one day" AppearanceMode="TextOnly" TextWrap="false" />
                  <syncfusion:ToolBarItem ID="tbiDailyScheduleToday_" Text="Today" ToolTip="Reset the report date to today's date" AppearanceMode="TextOnly" TextWrap="false" />                 
                  <syncfusion:ToolBarItem ID="tbiDailyScheduleMinus1Day_" Text="-1 Day" ToolTip="Decrease the report date by one day" AppearanceMode="TextOnly" TextWrap="false" />
                  <syncfusion:ToolBarItem ID="tbiDailyScheduleMinus1Week_" Text="-1 Week" ToolTip="Decrease the report date by one week" AppearanceMode="TextOnly" TextWrap="false" />
                  <syncfusion:ToolBarItem ID="tbiDailyScheduleMinus1Month_" Text="-1 Month" ToolTip="Decrease the report date by one month" AppearanceMode="TextOnly" TextWrap="False" />
                  <syncfusion:ToolBarItem ID="tbiSelectDate_" Text="Select Date" ButtonType="DropDown" TemplateID="tbtcCSelectDate_" />
                  <syncfusion:ToolBarItem Text="Item8" AppearanceMode="ImageOnly" ImageHoverPath="../CommonImages/Syncfusion_ToolBarSeperator.gif" 
                       ImagePath="../CommonImages/Syncfusion_ToolBarSeperator.gif" Look="emptylook" />
                  <syncfusion:ToolBarItem ID="tbiDailySchedulePrint_" Text="Print/PDF" ToolTip="Print the information displayed" AppearanceMode="TextOnly" TextWrap="False" />
                  <syncfusion:ToolBarItem ID="tbiDailyScheduleReport_" AppearanceMode="TextOnly" Disabled="True" Text="Report" TextWrap="False" ToolTip="Show the Comprehensive Report page" Visible="False" />
               </Items>
               <Templates>
                  <syncfusion:ToolBarTemplateControl ID="tbtcCSelectDate_" runat="server" ClientIDMode="Static">
                     <Template>
                        <syncfusion:DropDownCalendarControl ID="ddccDateSelection_" runat="server" AutoPostBackOnValueChanged="True" OnValueChanged="ddccDateSelection_onValueChaged_" ClientSideOnValueChange="ShowWaitingPopup_()" ClientIDMode="Static"
                           DayNameFormat="FirstLetter" CustomFormat="dd MMM yy" Format="CustomString" Width="100px" >
                        </syncfusion:DropDownCalendarControl>
                     </Template>
                  </syncfusion:ToolBarTemplateControl>
               </Templates>
            </syncfusion:ToolBar>         
Thanks,
 
James.
 

3 Replies

ES Ezhil S Syncfusion Team July 3, 2014 11:48 AM UTC

Hi James,

 

Thanks for your interest in Syncfusion products.

 

To set the date of the DropDownCalendar control embedded in ToolBar items using templates based on the selected items in toolbar, we suggest you to iterate the available controls in the Toolbar and find the DropDownCalendar control using the ID under ToolBar click event. Then you can set the date value for the control as required using Value property. Please refer the following code snippet,

 

<code>

[ASPX]

<syncfusion:ToolBar ID="tbDailySchedule_" runat="server" AutoFormat="Office2007 Blue" Width="100%" OnClick="Toolbar_Click_" Locked="True">

               <Items>

                  <syncfusion:ToolBarItem ID="tbiDailySchedulePlus1Month_" Text="+1 Month" ToolTip="Increase the report date by one month" AppearanceMode="TextOnly" TextWrap="false" />

                  <syncfusion:ToolBarItem ID="tbiDailySchedulePlus1Week_" Text="+1 Week" ToolTip="Increase the report date by one week" AppearanceMode="TextOnly" TextWrap="false" />

                  <syncfusion:ToolBarItem ID="tbiDailySchedulePlus1Day_" Text="+1 Day" ToolTip="Increase the report date by one day" AppearanceMode="TextOnly" TextWrap="false" />

                  <syncfusion:ToolBarItem ID="tbiDailyScheduleToday_" Text="Today" ToolTip="Reset the report date to today's date" AppearanceMode="TextOnly" TextWrap="false" />                 

                  <syncfusion:ToolBarItem ID="tbiDailyScheduleMinus1Day_" Text="-1 Day" ToolTip="Decrease the report date by one day" AppearanceMode="TextOnly" TextWrap="false" />

                  <syncfusion:ToolBarItem ID="tbiDailyScheduleMinus1Week_" Text="-1 Week" ToolTip="Decrease the report date by one week" AppearanceMode="TextOnly" TextWrap="false" />

                  <syncfusion:ToolBarItem ID="tbiDailyScheduleMinus1Month_" Text="-1 Month" ToolTip="Decrease the report date by one month" AppearanceMode="TextOnly" TextWrap="False" />

                  <syncfusion:ToolBarItem ID="tbiSelectDate_" Text="Select Date" ButtonType="DropDown" TemplateID="tbtcCSelectDate_" />

                  <syncfusion:ToolBarItem ID="tbiDailySchedulePrint_" Text="Print/PDF" ToolTip="Print the information displayed" AppearanceMode="TextOnly" TextWrap="False" />

                  <syncfusion:ToolBarItem ID="tbiDailyScheduleReport_" AppearanceMode="TextOnly" Disabled="True" Text="Report" TextWrap="False" ToolTip="Show the Comprehensive Report page" Visible="False" />

               </Items>

               <Templates>

                  <syncfusion:ToolBarTemplateControl ID="tbtcCSelectDate_" runat="server" ClientIDMode="Static">

                     <Template>

                        <syncfusion:DropDownCalendarControl ID="ddccDateSelection_" runat="server" AutoPostBackOnValueChanged="True" OnValueChanged="ddccDateSelection_onValueChaged_" ClientSideOnValueChange="ShowWaitingPopup_()" ClientIDMode="Static"

                           DayNameFormat="FirstLetter" CustomFormat="dd MMM yy" Format="CustomString" Width="100px" >

                        </syncfusion:DropDownCalendarControl>

                     </Template>

                  </syncfusion:ToolBarTemplateControl>

               </Templates>

            </syncfusion:ToolBar>

 

[CodeBehind]

        protected void Toolbar_Click_(object sender, Syncfusion.Web.UI.WebControls.Tools.ToolBarControl.ToolBarCommandEventArgs e)

        {

          

            foreach (Control control in tbDailySchedule_.Controls[0].Controls)

            {

                if (control.ID == "ddccDateSelection_")

                {

                    DropDownCalendarControl ddcl = (DropDownCalendarControl)control;

                    ddcl.CustomFormat = "MMM dd yyyy";

                    if (e.Item.ID == "tbiDailyScheduleToday_")

                        ddcl.Value = System.DateTime.Now;

                    if (e.Item.ID == "tbiDailyScheduleMinus1Day_")

                        ddcl.Value = System.DateTime.Now.AddDays(-1);

                    if (e.Item.ID == "tbiDailySchedulePlus1Day_")

                        ddcl.Value = System.DateTime.Now.AddDays(1);

                    if (e.Item.ID == "tbiDailySchedulePlus1Week_")

                        ddcl.Value = System.DateTime.Now.AddDays(7);

                    if (e.Item.ID == "tbiDailySchedulePlus1Month_")

                        ddcl.Value = System.DateTime.Now.AddMonths(1);

                    if (e.Item.ID == "tbiDailyScheduleMinus1Month_")

                        ddcl.Value = System.DateTime.Now.AddMonths(-1);

                    if (e.Item.ID == "tbiDailyScheduleMinus1Week_")

                        ddcl.Value = System.DateTime.Now.AddDays(-7);

                   

                }

            }           

        }

 

</code>

 

For your convenience we have modified your code to exhibit this behavior and it is available in the following link,

http://www.syncfusion.com/downloads/support/directtrac/general/Toolbar_f1169301956036904.zip

 

Kindly let us know if you have any other queries.

 

Regards,

Ezhil S



JK James Knowlton July 3, 2014 02:52 PM UTC

Thank you, that did the trick.


ES Ezhil S Syncfusion Team July 4, 2014 10:54 AM UTC

Hi James,

 

Thanks for the update.

 

We are glad to know that provided solution resolved the issue.

 

Hope we serve you better.

 

Kindly get back to us if you have further queries.

 

Regards,

Ezhil S


Loader.
Live Chat Icon For mobile
Up arrow icon