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

Combo on masterpage

1 Answer 57 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Stefania
Top achievements
Rank 2
Stefania asked on 07 Jan 2015, 04:40 PM
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?

1 Answer, 1 is accepted

Sort by
0
Ivan Danchev
Telerik team
answered on 12 Jan 2015, 12:36 PM
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.

 
Tags
ComboBox
Asked by
Stefania
Top achievements
Rank 2
Answers by
Ivan Danchev
Telerik team
Share this question
or