Combo on masterpage

2 posts, 0 answers
  1. Stefania
    Stefania avatar
    107 posts
    Member since:
    May 2013

    Posted 07 Jan 2015 Link to this post

    Hi,
    I have a combo and a menu on my masterpage. On combo selectedindexchanged I populate the menu.
    Each menu open a content page.
    When I click on a menu I lost the combo selection.

    <telerik:RadScriptManager ID="RadScriptManager1" runat="server"></telerik:RadScriptManager>
         <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
             <AjaxSettings>
                 <telerik:AjaxSetting AjaxControlID="ChooseProjectDdl">
                     <UpdatedControls>
                         <telerik:AjaxUpdatedControl ControlID="ChooseProjectDdl" />
                         <telerik:AjaxUpdatedControl ControlID="RadMenu1"  />
                         <telerik:AjaxUpdatedControl ControlID="BreadCrumbSiteMap"  />
                     </UpdatedControls>
                 </telerik:AjaxSetting>
     
                 <telerik:AjaxSetting AjaxControlID="RadMenu1">
                     <UpdatedControls>
                         <telerik:AjaxUpdatedControl ControlID="RadMenu1"  />
                         <telerik:AjaxUpdatedControl ControlID="ChooseProjectDdl" />
                         <telerik:AjaxUpdatedControl ControlID="BreadCrumbSiteMap"  />
                         <telerik:AjaxUpdatedControl ControlID="ContentPlaceHolder1"  />
                     </UpdatedControls>
                 </telerik:AjaxSetting>
             </AjaxSettings>
     
         </telerik:RadAjaxManager>
         <telerik:RadAjaxLoadingPanel ID="RadAjaxMainLoadingPanel" runat="server" Skin="Default" />
     
     
         <div>
     
             <header>              
                 <div class="projectChooser">
                     <telerik:RadComboBox ID="ChooseProjectDdl" runat="server" Width="250" Height="150" on
                         EmptyMessage="Select a Project" EnableLoadOnDemand="true"
                         OnSelectedIndexChanged="ChooseProjectDdl_SelectedIndexChanged" AutoPostBack="true"
                         Label="Project:">
                         <WebServiceSettings Method="GetUserProjects" Path="ProjectsWebService.asmx" />
                     </telerik:RadComboBox>            
                 </div>
             </header>
                        
     
                 <div class="demo-container size-medium no-bg">
                     <div class="demo-content">
                         <telerik:RadMenu ID="RadMenu1"
                             runat="server"
                             EnableRoundedCorners="true"
                             EnableShadows="true"
                             EnableTextHTMLEncoding="true"
                             Skin="Default">
                         </telerik:RadMenu>
                         <br />
                         <div class="breadcrumb">
                             <telerik:RadSiteMap ID="BreadCrumbSiteMap" runat="server" DataTextField="Text" DataNavigateUrlField="NavigateUrl" Skin="Silk">
                                 <DefaultLevelSettings ListLayout-RepeatDirection="Horizontal" SeparatorText="/" Layout="Flow" />
                             </telerik:RadSiteMap>
                             <h3>
                                 <asp:Literal runat="server" ID="PageTitleLiteral" />
                             </h3>
                         </div>
                     </div>
                 </div>
     
             
                 <asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">
                 </asp:ContentPlaceHolder>
            
         </div>

    I tried to save the value on a session and force the selectedvalue on the MasterPage on Load event but it doesn't work
    if (!Page.IsPostBack)
                {
                    if (Session["ActiveProject"] != null && GlobalClientInfo.LoggedUser != null)
                    {
                        ProjectEntity pjt = (ProjectEntity)Session["ActiveProject"];
                        m_ProjectId = pjt.Id;
                        ChooseProjectDdl.SelectedValue = m_ProjectId.ToString();
                    }
                }

    What do I miss?
  2. Ivan Danchev
    Admin
    Ivan Danchev avatar
    830 posts

    Posted 12 Jan 2015 Link to this post

    Hello,

    The problem that I noticed in your code is that you are trying to access the RadComboBox selection in the Session object only when the page is loaded for the first time (!Page.IsPostBack).
    Based on the provided information I assume that you store the RadComboBox SelectedValue to the Session object when  the RadComboBox OnSelectedIndexChanged event fires. 

    When the page is initially loaded the Session["ActiveProject"]  is null, as there is no selected item yet. To access the selected value from the Session on each post-back you can simply use the following syntax:
    //code behind
    if (Page.IsPostBack)
                {
                    if (Session["ActiveProject"] != null && GlobalClientInfo.LoggedUser != null)
                    {
                        ProjectEntity pjt = (ProjectEntity)Session["ActiveProject"];
                        m_ProjectId = pjt.Id;
                        ChooseProjectDdl.SelectedValue = m_ProjectId.ToString();
                    }
                }


    Regards,
    Ivan Danchev
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top