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

RadCombobox keeps old value on refresh

7 Answers 1017 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Daniel
Top achievements
Rank 1
Daniel asked on 21 Oct 2019, 03:30 PM

Hey guys,

 

I'm currently trying to achieve to have a specific year selected on initialize in the code behind. I try to select the current year by default and fill some years into the box. As soon as I switch the year and reload the page the radgrid takes the correct value but it gets displayed the old value (for example 2015) . Anyone has an Idea how to fix that? I already tried to clear all items before setting the datasource.

 

Thanks in advance,

Daniel

7 Answers, 1 is accepted

Sort by
0
Attila Antal
Telerik team
answered on 24 Oct 2019, 07:42 AM

Hi Daniel,

It sounds to me that the initial value is being re-set at every page load, even after selecting another record. Perhaps, you would need to use a condition to only set the selected value once, at initial load, but not repeat the process on other page loads/post backs.

Here is an example that can help you get a better understanding:

protected void Page_Init(object sender, EventArgs e)
{
    // Set the value every Post Back / Every time the page refreshes
    RadComboBox1.SelectedValue = "SomeValue";

    // Set the value only at initial load
    if (!IsPostBack)
    {
        RadComboBox1.SelectedValue = "SomeValue";
    }
}

 

If that is not the case, please share the code snippets you use so that we can see how things are configured and advise you accordingly.

 

Kind regards,
Attila Antal
Progress Telerik

Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
Daniel
Top achievements
Rank 1
answered on 24 Oct 2019, 07:56 AM

Hi Attila,

currently I am setting the Value on !IsPostBack here you can see the code I am using :

 

        If Not IsPostBack Then
            InitControls()
        End If
Protected Sub InitControls()
 
        ddl_user.ClearSelection()
        ddl_user.DataSource = getAllProcessHRUser()
        ddl_user.DataValueField = "UserName"
        ddl_user.DataTextField = "UserName"
        ddl_user.DataBind()
 
        If ddl_user.Items.Count() <> 0 Then
            ddl_user.FindItemByValue(User.Identity.Name.ToString()).Selected = True
        End If
 
 
    End Sub

 

So as far as my researches has come, he is always using the clientstate value if there is some value in it which gets not cleared on a refresh as it seems, on our system at least.

0
Attila Antal
Telerik team
answered on 24 Oct 2019, 03:53 PM

Hi Daniel,

If you're doing that, then the problem is lying somewhere else. Maybe there's a logic somewhere for clearing the value, or perhaps instead of the Post Back, the page redirects using the Response.Redirect() method.

 

Create a test page (test.aspx) and the following ComboBox Markup to it:

<telerik:RadComboBox ID="RadComboBox1" runat="server"></telerik:RadComboBox>
<br />
<br />
<telerik:RadButton ID="RadButton1" runat="server" Text="Post Back Button" AutoPostBack="true"></telerik:RadButton>

 

in the Code behind, bind data to the ComboBox using the IsPostBack condition:

Private Sub Page_Init(sender As Object, e As EventArgs) Handles Me.Init
    If Not IsPostBack Then
        RadComboBox1.DataSource = Enumerable.Range(1, 5).Select(Function(x) New With {
            Key .Value = x,
                .Text = "Item " & x
        })

        RadComboBox1.DataValueField = "Value"
        RadComboBox1.DataTextField = "Text"
        RadComboBox1.DataBind()

        If RadComboBox1.Items.Count() <> 0 Then
            RadComboBox1.FindItemByValue("2").Selected = True
        End If
    End If
End Sub

This will work as expected.

 

Nevertheless, if you can't find the issue, I would require more information to be able to help on this. It would be helpful if you could share the markup and code behind of the current page so that we can see what is being done.

 

Kind regards,
Attila Antal
Progress Telerik

Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
Daniel
Top achievements
Rank 1
answered on 25 Oct 2019, 06:33 AM

Hey Attila,

 

thanks for your reply.

 

We fixed the problem yesterday by moving the Combobox out of an Ajaxpanel. But I got the same Problem now on some RadDatePicker. but we believe it has to do with the Reload Button from the Radwindow because it is doing some kind of postback refresh instead of a clean refresh of the window

0
Attila Antal
Telerik team
answered on 25 Oct 2019, 07:55 AM

Hi Daniel,

Disabling AJAX is not the best solution to fix a problem unless having a scenario which is not supported out of the box. AJAX serves a good purpose, and so if the controls do not work while it's enabled, that means, that the AJAX request-response is not correct.

Eliminate the Nested AJAX from the page. If a control is placed inside an UpdatePanel or RadAjaxPanel, or it is added to the RadAjaxManager's AjaxSettings, ensure that childcontrols are not wrapped into an additional Update/Ajax Panel nor added to the RadAjaxManager's AjaxSettings. You can check out the following forum post showing the correct way of enabling AJAX, specially when using Master/Content pages and WebUserControls: Paging not work after the first Click

In any case, please share the markup as I would like to see how the components are created and initialized so that I can advise you accordingly.

Kind regards,
Attila Antal
Progress Telerik

Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
Daniel
Top achievements
Rank 1
answered on 25 Oct 2019, 08:00 AM

Hi Attila,

 

<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="Getaetigte_Aenderungen.aspx.vb"
    Inherits="ProcessHRWeb.Getaetigte_Aenderungen" Culture="auto" UICulture="auto" %>
 
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
<%@ Register TagPrefix="uc" TagName="FeedbackPanelBootstrap" Src="~/Controls/FeedbackPanelBootstrap.ascx" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<head runat="server">
    <title runat="server"></title>
    <style type='text/css'>
    </style>
    <link href="../styles/master.css" rel="stylesheet" type="text/css" />
    <link rel="stylesheet" type="text/css" href="../styles/hrBootstrap.css" />
    <link rel="stylesheet" type="text/css" href="../assets/css/bootstrap.css" />
</head>
<body id="content" bgcolor="#FFFFFF">
    <form id="form1" runat="server">
        <telerik:RadAjaxPanel ID="RadAjaxPanel1" runat="server" LoadingPanelID="LoadingPanel1"
            HorizontalAlign="NotSet" meta:resourcekey="RadAjaxPanel1Resource1">
        <telerik:RadCodeBlock runat="server">
        </telerik:RadCodeBlock>
        <telerik:RadStyleSheetManager ID="RadStyleSheetManager1" runat="server">
        </telerik:RadStyleSheetManager>
        <telerik:RadScriptManager ID="RadScriptManager1" runat="server">
        </telerik:RadScriptManager>
         
            <div id="div_master_top_bootstrap" style="width: auto; height: 25px">
                <div id="div_master_top_middle_bootstrap" class="rbDefault">
                    <uc:FeedbackPanelBootstrap ID="ucfeedbackPanelBootstrap" runat="server" class="rbDefault" />
                </div>
            </div>
            <telerik:RadComboBox ID="ddl_user" runat="server" Skin="Bootstrap" Width="250px" OnSelectedIndexChanged="ddl_user_SelectedIndexChanged" AutoPostBack="true"
                Height="250px">
                <CollapseAnimation Duration="200" Type="OutQuint" />
                <%--                        <Items>
                            <telerik:RadComboBoxItem runat="server" Text="Alle" Value="All" />
                        </Items>--%>
            </telerik:RadComboBox>
            <telerik:RadDatePicker runat="server" ID="rdpDatumVon" Skin="Bootstrap" DateInput-Label="Von" DateInput-LabelWidth="25%" DateInput-CausesValidation="false" OnSelectedDateChanged="rdpDatumVon_SelectedDateChanged" AutoPostBack="true"></telerik:RadDatePicker>
            <telerik:RadDatePicker runat="server" ID="rdpDatumBis" Skin="Bootstrap" DateInput-Label="Bis" DateInput-LabelWidth="25%" DateInput-CausesValidation="false" OnSelectedDateChanged="rdpDatumBis_SelectedDateChanged" AutoPostBack="true"></telerik:RadDatePicker>
            <telerik:RadGrid ID="RadGrid_Aenderungen" runat="server"
                OnNeedDataSource="RadGrid_Aenderungen_NeedDataSource"
                ShowStatusBar="false" AllowPaging="true" GridLines="None" AutoGenerateColumns="False" OnItemDataBound="RadGrid_Aenderungen_ItemDataBound"
                Skin="Bootstrap" Style="margin-top: 7px; margin-left: 0px; margin-right: 5px; margin-bottom: 5px;">
                <ExportSettings OpenInNewWindow="True">
                    <Pdf PaperSize="A4" PageHeight="210mm" PageWidth="297mm" />
                </ExportSettings>
                <MasterTableView AllowMultiColumnSorting="True"
                    AllowSorting="True" NoDetailRecordsText="Keine Daten vorhanden." PageSize="20" PagerStyle-Position="Bottom"
                    NoMasterRecordsText="Keine Daten vorhanden." TableLayout="Fixed">
                    <Columns>
                        <telerik:GridBoundColumn DataField="AendungsArtConst" HeaderText="#Art der Änderung"
                            ReadOnly="True" SortExpression="AendungsArtConst" UniqueName="AendungsArtConst">
                            <HeaderStyle Width="115px" />
                        </telerik:GridBoundColumn>
                        <telerik:GridTemplateColumn>
                            <HeaderTemplate>
                                <asp:Label ID="lblNameGesamtHeader" runat="server" Text='<%# TranslateText("Name Gesamt")%>'></asp:Label>
                            </HeaderTemplate>
                            <ItemTemplate>
                                <asp:Label ID="lblNameGesamt" runat="server" Text='<%# ReturnFullName(DataBinder.Eval(Container, "DataItem.hr_m_personal")) %>'></asp:Label>
                            </ItemTemplate>
                        </telerik:GridTemplateColumn>
                        <%--                    <telerik:GridBoundColumn DataField="NameGesamt" HeaderText="#Name Gesamt" ReadOnly="True"
                        SortExpression="NameGesamt" UniqueName="NameGesamt">
                        <HeaderStyle Width="150px" />
                    </telerik:GridBoundColumn>--%>
                        <telerik:GridBoundColumn DataField="datum_von" HeaderText="#Von" DataType="System.DateTime"
                            DataFormatString="{0:dd.MM.yyyy}" ReadOnly="True" SortExpression="datum_von"
                            UniqueName="datum_von">
                            <HeaderStyle Width="85px" />
                        </telerik:GridBoundColumn>
                        <telerik:GridBoundColumn DataField="datum_bis" HeaderText="#Bis" DataType="System.DateTime"
                            DataFormatString="{0:dd.MM.yyyy}" ReadOnly="True" SortExpression="datum_bis"
                            UniqueName="datum_bis">
                            <HeaderStyle Width="85px" />
                        </telerik:GridBoundColumn>
                        <telerik:GridBoundColumn DataField="uhrzeit_von" HeaderText="#Uhrzeit von" DataType="System.DateTime"
                            DataFormatString="{0:HH:mm}" ReadOnly="True" SortExpression="uhrzeit_von" UniqueName="uhrzeit_von">
                            <HeaderStyle Width="85px" />
                        </telerik:GridBoundColumn>
                        <telerik:GridBoundColumn DataField="uhrzeit_bis" HeaderText="#Uhrzeit bis" DataType="System.DateTime"
                            DataFormatString="{0:HH:mm}" ReadOnly="True" SortExpression="uhrzeit_bis" UniqueName="uhrzeit_bis">
                            <HeaderStyle Width="85px" />
                        </telerik:GridBoundColumn>
                        <telerik:GridTemplateColumn>
                            <HeaderTemplate>
                                <asp:Label ID="lblAbwesenheitHeader" runat="server" Text='<%# TranslateText("Abwesenheit")%>'></asp:Label>
                            </HeaderTemplate>
                            <ItemTemplate>
                                <asp:Label ID="lblAbwesenheitBezeichnung" runat="server" Text='<%# ReturnAbwesenheitBezeichnung(DataBinder.Eval(Container, "DataItem.hr_m_abwesenheit_id"))%>'></asp:Label>
                            </ItemTemplate>
                        </telerik:GridTemplateColumn>
                        <%--<telerik:GridBoundColumn DataField="abwesenheit_bezeichnung" HeaderText="#Abwesenheit"
                        ReadOnly="True" SortExpression="abwesenheit_bezeichnung" UniqueName="abwesenheit_bezeichnung">
                        <HeaderStyle Width="115px" />
                    </telerik:GridBoundColumn--%>
                        <telerik:GridTemplateColumn>
                            <HeaderTemplate>
                                <asp:Label ID="lblSchichtBezeichnungHeader" runat="server" Text='<%# TranslateText("Schicht") %>'></asp:Label>
                            </HeaderTemplate>
                            <ItemTemplate>
                                <asp:Label ID="lblSchichtBezeichnung" runat="server" Text='<%# ReturnSchichtBezeichnung(DataBinder.Eval(Container, "DataItem.hr_m_schicht_id")) %>'></asp:Label>
                            </ItemTemplate>
                        </telerik:GridTemplateColumn>
                        <%--<telerik:GridBoundColumn DataField="schicht_bezeichnung" HeaderText="#Schicht" ReadOnly="True"
                        SortExpression="schicht_bezeichnung" UniqueName="schicht_bezeichnung">
                        <HeaderStyle Width="115px" />
                    </telerik:GridBoundColumn>--%>
                        <telerik:GridTemplateColumn>
                            <HeaderTemplate>
                                <asp:Label ID="lblArbeitsplatzBezeichnungHeader" runat="server" Text='<%# TranslateText("Arbeitsplatz") %>'></asp:Label>
                            </HeaderTemplate>
                            <ItemTemplate>
                                <asp:Label ID="lblArbeitsplatzBezeichnung" runat="server" Text='<%# ReturnArbeitsplatzBezeichnung(DataBinder.Eval(Container, "DataItem.hr_m_arbeitsplatz_id")) %>'></asp:Label>
                            </ItemTemplate>
                        </telerik:GridTemplateColumn>
                        <%--                    <telerik:GridBoundColumn DataField="arbeitsplatz_bezeichnung" HeaderText="#Arbeitsplatz"
                        ReadOnly="True" SortExpression="arbeitsplatz_bezeichnung" UniqueName="arbeitsplatz_bezeichnung">
                        <HeaderStyle Width="115px" />
                    </telerik:GridBoundColumn>--%>
                        <telerik:GridBoundColumn DataField="danl" DataType="System.DateTime" HeaderText="#Angelegt am"
                            ReadOnly="True" SortExpression="danl" UniqueName="danl">
                            <HeaderStyle Width="85px" />
                        </telerik:GridBoundColumn>
                        <telerik:GridBoundColumn DataField="uidanl" HeaderText="#Angelegt von" ReadOnly="True"
                            SortExpression="uidanl" UniqueName="uidanl">
                            <HeaderStyle Width="85px" />
                        </telerik:GridBoundColumn>
                        <telerik:GridBoundColumn DataField="dlae" DataType="System.DateTime" HeaderText="#Geändert am"
                            ReadOnly="True" SortExpression="dlae" UniqueName="dlae">
                            <HeaderStyle Width="85px" />
                        </telerik:GridBoundColumn>
                        <telerik:GridBoundColumn DataField="uidlae" HeaderText="Geändert von" ReadOnly="True"
                            SortExpression="uidlae" UniqueName="uidlae">
                            <HeaderStyle Width="85px" />
                        </telerik:GridBoundColumn>
                    </Columns>
                    <SortExpressions>
                        <telerik:GridSortExpression FieldName="dlae" SortOrder="Descending" />
                    </SortExpressions>
                </MasterTableView>
                <FilterMenu EnableTheming="True" Skin="Bootstrap">
                    <CollapseAnimation Duration="200" Type="OutQuint" />
                </FilterMenu>
                <HeaderContextMenu EnableTheming="True" Skin="Bootstrap">
                    <CollapseAnimation Duration="200" Type="OutQuint" />
                </HeaderContextMenu>
                <PagerStyle Mode="NumericPages"></PagerStyle>
            </telerik:RadGrid>
        
        <%-- <div id="div_master_content" style="top: 15px; visibility: hidden">
            <table bordercolor="#8DB3E4" border="1">
                <tr>
                    <td background="../images/toolbar/toolbar.gif" style="height: 40px" valign="middle"
                        colspan="2">
                        <asp:Label ID="lbl_aenderungen" runat="server" Text="#Letzte Änderungen" CssClass="content_element"
                            Font-Bold="True"></asp:Label>
                    </td>
                </tr>
                <tr>
                    <td>
                        <asp:Label ID="lbl_user" runat="server" Text="Benutzer:" CssClass="content_element"
                            Font-Bold="True"></asp:Label>
                    </td>
                    <td>
                         
                    </td>
                </tr>
                <tr>
                    <td>
                        <asp:Label ID="lbl_jahr" runat="server" Text="#Jahr:" CssClass="content_element" Font-Bold="True"></asp:Label>
                    </td>
                    <td>
 
                    </td>
                </tr>
                <tr>
                    <td valign="top" colspan="2">
 
                    </td>
                </tr>
            </table>
        </div>--%>
 
        <asp:TextBox ID="txt_ap_message" runat="server" Text="Bitte wählen Sie einen Arbeitsplatz aus!"
            Style="visibility: hidden" meta:resourcekey="txt_ap_messageResource1"></asp:TextBox>
        <asp:TextBox ID="txt_ma_message" runat="server" Text="Bitte wählen Sie einen Mitarbeiter aus!"
            Style="visibility: hidden" meta:resourcekey="txt_ma_messageResource1"></asp:TextBox>
        </telerik:RadAjaxPanel>
        <telerik:RadAjaxLoadingPanel ID="LoadingPanel1" runat="server" Height="21px" HorizontalAlign="Center"
            Skin="Bootstrap" Transparency="20" Width="200px" Style="left: 0px; position: relative; top: 0px"
            BackColor="#C3DAF9">
        </telerik:RadAjaxLoadingPanel>
        <%--<telerik:RadAjaxManager ID="RadAjaxManager1" runat="server" DefaultLoadingPanelID="LoadingPanel1">
            <AjaxSettings>
                <telerik:AjaxSetting AjaxControlID="ddl_user">
                    <UpdatedControls>
                        <telerik:AjaxUpdatedControl ControlID="RadGrid_Aenderungen" />
                    </UpdatedControls>
                </telerik:AjaxSetting>
                <telerik:AjaxSetting AjaxControlID="cbx_year">
                    <UpdatedControls>
                        <telerik:AjaxUpdatedControl ControlID="RadGrid_Aenderungen" />
                    </UpdatedControls>
                </telerik:AjaxSetting>
                <telerik:AjaxSetting AjaxControlID="RadGrid_Aenderungen">
                    <UpdatedControls>
                        <telerik:AjaxUpdatedControl ControlID="RadGrid_Aenderungen" />
                    </UpdatedControls>
                </telerik:AjaxSetting>
            </AjaxSettings>
        </telerik:RadAjaxManager>--%>
    </form>
 
</body>
</html>

 

 

this is the markup we use

0
Attila Antal
Telerik team
answered on 25 Oct 2019, 08:44 AM

Hi Daniel,

Thanks for sharing the markup. I can see now what you meant by disabling AJAX. Basically, you have eliminated the Nested AJAX structure.

Every control inside an UpdatePanel, RadAjaxPanel is already Ajaxified. Enabling AJAX for the controls in these panels additionally by using the RadAjaxManager, will result in nested AJAX Panels and that definitely prevents the control from proper functioning. 

Furthermore, I see that everything is placed inside the AJAX panel. I would advise only include controls in the update panel you need to updated, not the entire page.

Also, I advise changing the structure of the page where the ScriptManager is the first control inside the form and everything else comes after.

<form id="Form2" runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
    <telerik:RadAjaxPanel ID="RadAjaxPanel1" runat="server">
        <%--CONTROLS--%>
    </telerik:RadAjaxPanel>
</form>

Kind regards,
Attila Antal
Progress Telerik

Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
ComboBox
Asked by
Daniel
Top achievements
Rank 1
Answers by
Attila Antal
Telerik team
Daniel
Top achievements
Rank 1
Share this question
or