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

RadCombBox on Modal RadWindow SelectedValue Issue

1 Answer 174 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Michael
Top achievements
Rank 2
Iron
Iron
Iron
Michael asked on 24 Jan 2012, 10:02 PM
I have a RadWindow configured to be opened via a "username" hyperlink on my master page - this RadWindow is setup to allow impersonation of other users for the purpose of troublshooting issues.  The first RadComboBox is populated server side while the second combo box is dynamically populated but is tied to the selected value from the first RadComboBox.  For some reason when I change the selected value in the first RadComboBox that value is not being transferred back to the server but dynamic data I type into the second RadComboBox which has EnableLoadOnDemand set to true does - since both controls are on the RadWindow I can see no reason why the updated selected value (altered from when combo was first loaded) is not - below you will find the markup for the RadWindow and the server side event for the second RadComboBox that is using the selected value from the first - any thoughts/help would be much appreciated as I am pulling my hair out - please note that I've stepped through the code and the code that loads the first combo box is not being called on postback (which would reset the combobox) so I don't think that is the issue.

<telerik:RadWindow ID="ImpersonationWindow" runat="server" Height="200px" Width="500px" IconUrl="/Content/Images/user16.png"
					Animation="Fade" Modal="true" Title="User Impersonation" Behaviors="Close" KeepInScreenBounds="true" 
					ReloadOnShow="false" DestroyOnClose="false">
					<ContentTemplate>
						<div class="row">
							<span class="label" style="width30%;">
								<span class="small-red-bold-label">Business Unit:</span>
							</span>
							<span class="field" style="width65%;">
								<telerik:RadComboBox ID="ImpersonatedBusinessUnitRadComboBox" runat="server" Width="275px" CausesValidation="false"
									DataTextField="FormalName" DataValueField="CentralBusinessUnitNo">
								</telerik:RadComboBox>
							</span>
						</div>
						<div class="row">
							<span class="label" style="width30%;">
								<span class="small-red-bold-label">Employee:</span>
							</span>
							<span class="field" style="width65%;">
								<telerik:RadComboBox ID="ImpersonatedEmployeeRadComboBox" runat="server" Width="275px" Height="200px" CausesValidation="false"
									DataValueField="EmpID" DataTextField="FullName" 
									ShowDropDownOnTextboxClick="false" EnableLoadOnDemand="true" MarkFirstMatch="false" ItemRequestTimeout="500"
									EmptyMessage="Type Employee Name..." MinFilterLength="2" OnItemsRequested="ImpersonatedEmployeeRadComboBox_ItemsRequested">
								</telerik:RadComboBox>
							</span>
						</div>
						<div class="row"><span class="label"></span><span class="field"></span></div>
						<div class="row">
							<span class="label" style="width48%;">
								<asp:Button ID="ImpersonateButton" runat="server" Text="Impersonate" Width="100px" OnClick="ImpersonateButton_Click" />
							</span>
							<span class="field" style="width48%;">
								<asp:Button ID="ResetButton" runat="server" Text="Reset" Width="100px" OnClick="ResetButton_Click" />
							</span>
						</div>
					</ContentTemplate>
				</telerik:RadWindow>


protected void ImpersonatedEmployeeRadComboBox_ItemsRequested(object sender,RadComboBoxItemsRequestedEventArgs e)
        {
            if(!string.IsNullOrEmpty(e.Text))
            {
                if(e.Text.Length >= 2)
                {
                    List<FindEmployeeView> employees = new List<FindEmployeeView>();
                    // get data from data context
                    using(CommonDataContext context = new CommonDataContext(ConfigurationManager.ConnectionStrings["CEO"].ConnectionString))
                    {
                        employees = 
                            context.FindEmployeesByFullName(
                                0,
                                e.Text,
                                AnyOrganizationFilter,
                                "|" + ImpersonatedBusinessUnitRadComboBox.SelectedValue + "|",
                                AnyOrganizationFilter,
                                1).ToList();
                    }
                    // databind
                    ImpersonatedEmployeeRadComboBox.DataSource = employees;
                    ImpersonatedEmployeeRadComboBox.DataBind();
                }
            }
        }

1 Answer, 1 is accepted

Sort by
0
Michael
Top achievements
Rank 2
Iron
Iron
Iron
answered on 25 Jan 2012, 05:37 PM
I have solved the problem.  After perusing the forum postings I came across an article that gave me the solution.  I am using the ClientItemsRequesting event for the RadComboBox that does "LoadOnDemand" and taking the selected value from the first RadComboBox and adding it as an item in the context object of second RadComboBox.  On the server side instead of using the SelectedValue property of the first RadComboBox (which was not reflecting client selected value) I am now using the item from the context object and it works like a charm.  Code is shown below, first client script, then server side code:

//Function Name: ImpersonatedEmployeeRadComboBox_ClientItemsRequesting
//Function Purpose: Handle the client side item requesting event for the ImpersonatedEmployeeRadComboBox.
//Function Author: Michael A. Jensen
function ImpersonatedEmployeeRadComboBox_ClientItemsRequesting(sender, eventArgs) {
  
    // define local variables
    var debug = false;
  
    // put function code within try-catch-finally block
    try {
        // debug purposes only - set debug = true to view
        if (debug) alert(">>Entered JavaScript:ImpersonatedEmployeeRadComboBox_ClientItemsRequesting");
  
        var context = eventArgs.get_context();
        var combo = $find("ctl00_ImpersonationWindow_C_ImpersonatedBusinessUnitRadComboBox");
        var value = combo.get_value();
        if (debug) alert("context = " + context + ", combo = " + combo + ", value = " + value);
        context["CentralBusinessUnitNo"] = value;
    }
    catch (ex) {
        var msg = "JavaScript:ImpersonatedEmployeeRadComboBox_ClientItemsRequesting failed. "
        alert(msg + ex.message);
    }
    finally {
        // debug purposes only - set debug = true to view
        if (debug) alert("<<Exiting JavaScript:ImpersonatedEmployeeRadComboBox_ClientItemsRequesting");
    }
}

protected void ImpersonatedEmployeeRadComboBox_ItemsRequested(object sender,RadComboBoxItemsRequestedEventArgs e)
        {
            if(!string.IsNullOrEmpty(e.Text))
            {
                if(e.Text.Length >= 2)
                {
                    List<FindEmployeeView> employees = new List<FindEmployeeView>();
                    // get data from data context
                    using(CommonDataContext context = new CommonDataContext(ConfigurationManager.ConnectionStrings["CEO"].ConnectionString))
                    {
                        employees = 
                            context.FindEmployeesByFullName(
                                0,
                                e.Text,
                                AnyOrganizationFilter,
                                "|" + e.Context["CentralBusinessUnitNo"].ToString() + "|",
                                AnyOrganizationFilter,
                                1).ToList();
                    }
                    // databind
                    ImpersonatedEmployeeRadComboBox.DataSource = employees;
                    ImpersonatedEmployeeRadComboBox.DataBind();
                }
            }
        }
Tags
ComboBox
Asked by
Michael
Top achievements
Rank 2
Iron
Iron
Iron
Answers by
Michael
Top achievements
Rank 2
Iron
Iron
Iron
Share this question
or