RadAjaxManager to update label control

9 posts, 1 answers
  1. Carlos Eduardo Nogueira
    Carlos Eduardo Nogueira avatar
    15 posts
    Member since:
    Jul 2009

    Posted 09 Sep 2009 Link to this post

    Hi!

    I have a doubt. In my page I use RadAjaxManager when I have an action in my RadGrid and, independent or not of exception, I would like to show a message in a label. The code you can see below:

    <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server" OnAjaxRequest="RadAjaxManager1_AjaxRequest">
    <AjaxSettings>
        <telerik:AjaxSetting AjaxControlID="RadAjaxManager1">
            <UpdatedControls>
                <telerik:AjaxUpdatedControl ControlID="rgVeiculos" LoadingPanelID="RadAjaxLoadingPanel1" />
            </UpdatedControls>
            <UpdatedControls>
                <telerik:AjaxUpdatedControl ControlID="rcbVeiculo" LoadingPanelID="RadAjaxLoadingPanel1" />
            </UpdatedControls>
            <UpdatedControls>
                <telerik:AjaxUpdatedControl ControlID="rcbClassificacao" LoadingPanelID="RadAjaxLoadingPanel1" />
            </UpdatedControls>
        </telerik:AjaxSetting>      
        
        <telerik:AjaxSetting AjaxControlID="rgVeiculos">
            <UpdatedControls>
                <telerik:AjaxUpdatedControl ControlID="rgVeiculos" LoadingPanelID="RadAjaxLoadingPanel1" />
            </UpdatedControls>
            <UpdatedControls>
                <telerik:AjaxUpdatedControl ControlID="trMensagem" LoadingPanelID="RadAjaxLoadingPanel1" />
            </UpdatedControls>
        </telerik:AjaxSetting>  
        
        <telerik:AjaxSetting AjaxControlID="btnBuscarVeiculos">
            <UpdatedControls>
                <telerik:AjaxUpdatedControl ControlID="rcbVeiculo" LoadingPanelID="RadAjaxLoadingPanel1" />
            </UpdatedControls>
            <UpdatedControls>
                <telerik:AjaxUpdatedControl ControlID="rcbClassificacao" LoadingPanelID="RadAjaxLoadingPanel1" />
            </UpdatedControls>
        </telerik:AjaxSetting>                                                           
        
        <telerik:AjaxSetting AjaxControlID="btnBuscarClassif">
            <UpdatedControls>
                <telerik:AjaxUpdatedControl ControlID="rcbClassificacao" LoadingPanelID="RadAjaxLoadingPanel1" />
            </UpdatedControls>
        </telerik:AjaxSetting>                                                           
        
    </AjaxSettings>
    </telerik:RadAjaxManager>

    <telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server" Skin="Telerik" >
    </telerik:RadAjaxLoadingPanel>


    I will put the code of RadGrid:
                            <telerik:RadGrid ID="rgVeiculos" Width="100%" Skin="Telerik"
                                runat="server" AllowPaging="true" AllowSorting="true"
                                GridLines="None"  AutoGenerateColumns="false" PageSize="20"
                                OnItemCreated="rgVeiculos_ItemCreated"
                                OnNeedDataSource="rgVeiculos_NeedDataSource"
                                OnDeleteCommand="rgVeiculos_DeleteCommand">
                                <MasterTableView GridLines="None" DataKeyNames="IdFrotaModelo" Name="TableViewVeiculos">
                                    <Columns>
                                        <telerik:GridBoundColumn UniqueName="Fabricante" HeaderText="Fabricante" DataField="Fabricante" ItemStyle-HorizontalAlign="Left" HeaderStyle-HorizontalAlign="Left"></telerik:GridBoundColumn>
                                        <telerik:GridBoundColumn UniqueName="Veiculo" HeaderText="Veículo" DataField="Veiculo" ItemStyle-HorizontalAlign="Left" HeaderStyle-HorizontalAlign="Left"></telerik:GridBoundColumn>
                                        <telerik:GridBoundColumn UniqueName="Classificacao" HeaderText="Classificação" DataField="Classificacao" ItemStyle-HorizontalAlign="Left" HeaderStyle-HorizontalAlign="Left"></telerik:GridBoundColumn>
                                        <telerik:GridBoundColumn UniqueName="Categoria" HeaderText="Categorias Habilitação" DataField="Categorias" ItemStyle-HorizontalAlign="Left" HeaderStyle-HorizontalAlign="Left"></telerik:GridBoundColumn>
                                        
                                        <telerik:GridTemplateColumn UniqueName="TemplateEditColumn">
                                            <ItemTemplate>
                                                <asp:HyperLink ID="EditLink" runat="server" Text="Editar"></asp:HyperLink>
                                            </ItemTemplate>
                                        </telerik:GridTemplateColumn>
                                        <telerik:GridButtonColumn UniqueName="DeleteColumn" Text="Remove" CommandName="Delete" ConfirmTitle="Exclusão" ConfirmText="Deseja realmente excluir este veículo?" ItemStyle-HorizontalAlign="Left" HeaderStyle-HorizontalAlign="Left" HeaderStyle-Width="60px"></telerik:GridButtonColumn>
                                    </Columns>
                                </MasterTableView>
                            </telerik:RadGrid>


    I will put the code I use for label:
                    <tr id="trMensagem" runat="server" visible="false">
                        <td valign="middle">
                            <asp:Panel ID="pnlMsg" runat="server" BackColor="#FFFFAA" Height="25px">
                                &nbsp;&nbsp;<asp:Label ID="lblResultado" runat="server" Text="" Font-Names="Verdana" Font-Size="9"></asp:Label>
                            </asp:Panel>
                        </td>
                    </tr>

    So, If I try to remove some item of my grid, I would like to show a message for the user, but nothing occur in a page. In a code behind, I try something like this:

    trMensagem.Visible = true;
    lblResultado.Text = "Message for user";


    Someone know how I can overcome this problem?
  2. ManniAT
    ManniAT avatar
    877 posts
    Member since:
    Nov 2003

    Posted 09 Sep 2009 Link to this post

    Hi Carlos,

    from my experiences AjaxSettings are not cascading.
    So for a typical grid (and a label) it could look like this:

    <AjaxSettings>
        <telerik:AjaxSetting AjaxControlID="myButton">
            <UpdatedControls>
                <telerik:AjaxUpdatedControl ControlID="myGrid" />
                <telerik:AjaxUpdatedControl ControlID="myLabel1" />
            </UpdatedControls>
        </telerik:AjaxSetting>

        <telerik:AjaxSetting AjaxControlID="myGrid">
            <UpdatedControls>
                <telerik:AjaxUpdatedControl ControlID="myOtherLabel" />
            </UpdatedControls>
        </telerik:AjaxSetting>
    </AjaxSettings>

    This would mean - if I press myButton myGrid and myLabel1 are updated.
    If I do something with the grid - the other label should be updated.
    BUT - if myButton does something with the grid (in code behind) - myOtherLabel1 is NOT updated!!!

    So in your case - you have to place your label as updated control to every setting which affects the control.
    For your sample - if the AjaxManager itself (somehow) affects the grid and that should affect the label also then
    you have to place your label in the same ajax setting as the grid.
    The same for btnBuscarVehi....

    And by the way - there is no need to open several updatedcontrol sections (take a look at the code above).

    To bring the thing to code:
    <AjaxSettings>
        <telerik:AjaxSetting AjaxControlID="USER_INTERACTION_WITH_myButton_RESULTS_IN_CALLBACK">
            <UpdatedControls>
                <telerik:AjaxUpdatedControl ControlID="UPDATE_myGrid" />
                <telerik:AjaxUpdatedControl ControlID="AND_ALSO_UPDATE_myLabel1" />
            </UpdatedControls>
        </telerik:AjaxSetting>

        <telerik:AjaxSetting AjaxControlID="USER_INTERACTION_WITH_myGrid_RESULTS_IN_CALLBACK">
            <UpdatedControls>
                <telerik:AjaxUpdatedControl ControlID="UPDATE_myOtherLabel" />
            </UpdatedControls>
        </telerik:AjaxSetting>
    </AjaxSettings>

    Regards
    Manfred
    PS: if this post was helpful please use "Mark as answer"
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Carlos Eduardo Nogueira
    Carlos Eduardo Nogueira avatar
    15 posts
    Member since:
    Jul 2009

    Posted 10 Sep 2009 Link to this post

    Hi Manfred,

    In this case, I changed my html code as you can see below:

    <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server" OnAjaxRequest="RadAjaxManager1_AjaxRequest">
    <AjaxSettings>
        <telerik:AjaxSetting AjaxControlID="RadAjaxManager1">
            <UpdatedControls>
                <telerik:AjaxUpdatedControl ControlID="rgCategorias" LoadingPanelID="RadAjaxLoadingPanel1" />
                <telerik:AjaxUpdatedControl ControlID="rcbCategoria" LoadingPanelID="RadAjaxLoadingPanel1" />
                <telerik:AjaxUpdatedControl ControlID="trMensagem" LoadingPanelID="RadAjaxLoadingPanel1" />
            </UpdatedControls>
        </telerik:AjaxSetting>      
        <telerik:AjaxSetting AjaxControlID="rgCategorias">
            <UpdatedControls>
                <telerik:AjaxUpdatedControl ControlID="rgCategorias" LoadingPanelID="RadAjaxLoadingPanel1" />
                <telerik:AjaxUpdatedControl ControlID="rcbCategoria" LoadingPanelID="RadAjaxLoadingPanel1" />
                <telerik:AjaxUpdatedControl ControlID="trMensagem" LoadingPanelID="RadAjaxLoadingPanel1" />
            </UpdatedControls>
        </telerik:AjaxSetting>                                                             
    </AjaxSettings>
    </telerik:RadAjaxManager>


    So, When I do some test to show the message, I'm still with the same problem. In code behind, I have something like this:

        protected void rgCategorias_DeleteCommand(object sender, Telerik.Web.UI.GridCommandEventArgs e)
        {
            try
            {
                CategoriaCNH categoria = new CategoriaCNH();

                GridEditableItem editedItem = e.Item as GridEditableItem;

                int idcategoria = int.Parse(editedItem.OwnerTableView.DataKeyValues[editedItem.ItemIndex]["IdCategoriaCNH"].ToString());
                categoria.IdCategoriaCNH = idcategoria;
                categoria.Remove();

                CarregaComboCategoria(rcbCategoria);
                OcultaMsgPagina(true);
            }
            catch (Exception ex)
            {
                ExibirMensagem(true, ex.Message);
            }
        }

        private void ExibirMensagem(bool _msgErro, string _textoMsg)
        {
            try
            {
                OcultaMsgPagina(false);
                if (_msgErro)
                {
                    lblResultado.ForeColor = System.Drawing.Color.Red;
                    lblResultado.Text = _textoMsg;

                }
                else
                {
                    lblResultado.ForeColor = System.Drawing.Color.Black;
                    lblResultado.Text = _textoMsg;

                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        private void OcultaMsgPagina(bool oculta)
        {
            trMensagem.Visible = !oculta;
        }

    In Remove() method, I have a condition to throw an exception if it's true. When throw an exception, I call the ExibirMensagem() method to show the message on page by ex.Message property. But, the trMensagem object (my tag tr in html as you can see in first post) don't become visible and my label (lblResultado) is in it.

    Is there anything I can do besides this post to solve my problem?

    Regards,
    Carlos
    PS: My apologies by my english
  5. ManniAT
    ManniAT avatar
    877 posts
    Member since:
    Nov 2003

    Posted 10 Sep 2009 Link to this post

    Holla Carlos,

    let's have a contest who's english is more worse :)

    Anyhow - I've overseen the TR / LABEL thing in your first post.
    It would be better (for readability) to use the "Format Codeblock" button on top of the page when you paste code.

    How ever - you change TWO controls.
    First the TR which becomes visible - and next the Label - where you change the text.
    So please enhance your Ajax settings (both) with updatedcontrol - lblResultado

    Regards
    Manfred
    PS: if this post was helpful please use "Mark as answer"
  6. Carlos Eduardo Nogueira
    Carlos Eduardo Nogueira avatar
    15 posts
    Member since:
    Jul 2009

    Posted 10 Sep 2009 Link to this post

    Hi Manfred,

    I did that you said, but I'm still with the same problem. Let's see the html code:
    <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server" OnAjaxRequest="RadAjaxManager1_AjaxRequest"
    <AjaxSettings> 
        <telerik:AjaxSetting AjaxControlID="RadAjaxManager1"
            <UpdatedControls> 
                <telerik:AjaxUpdatedControl ControlID="rgCategorias" LoadingPanelID="RadAjaxLoadingPanel1" /> 
                <telerik:AjaxUpdatedControl ControlID="rcbCategoria" LoadingPanelID="RadAjaxLoadingPanel1" /> 
                <telerik:AjaxUpdatedControl ControlID="trMensagem" LoadingPanelID="RadAjaxLoadingPanel1" /> 
                <telerik:AjaxUpdatedControl ControlID="lblResultado" LoadingPanelID="RadAjaxLoadingPanel1" /> 
            </UpdatedControls> 
        </telerik:AjaxSetting>       
        <telerik:AjaxSetting AjaxControlID="rgCategorias"
            <UpdatedControls> 
                <telerik:AjaxUpdatedControl ControlID="rgCategorias" LoadingPanelID="RadAjaxLoadingPanel1" /> 
                <telerik:AjaxUpdatedControl ControlID="rcbCategoria" LoadingPanelID="RadAjaxLoadingPanel1" /> 
                <telerik:AjaxUpdatedControl ControlID="trMensagem" LoadingPanelID="RadAjaxLoadingPanel1" /> 
                <telerik:AjaxUpdatedControl ControlID="lblResultado" LoadingPanelID="RadAjaxLoadingPanel1" /> 
            </UpdatedControls> 
        </telerik:AjaxSetting>                                                              
    </AjaxSettings> 
    </telerik:RadAjaxManager> 

                    <tr id="trMensagem" runat="server" visible="false"
                        <td valign="middle"
                            <asp:Panel ID="pnlMsg" runat="server" BackColor="#FFFFAA" Height="25px"
                                &nbsp;&nbsp;<asp:Label ID="lblResultado" runat="server" Text="" Font-Names="Verdana" Font-Size="9"></asp:Label> 
                            </asp:Panel> 
                        </td> 
                    </tr> 




    Do you think it's necessary to add the panel control in Ajax settings with updatecontrol?

    Regards
    Carlos

  7. ManniAT
    ManniAT avatar
    877 posts
    Member since:
    Nov 2003

    Posted 10 Sep 2009 Link to this post

    You should give it a try.
    And maybe you could rethink if you need a the panel inside the TD in the TR.
    If it is just for background color and height - you could set it also via a style in the TD.
  8. Carlos Eduardo Nogueira
    Carlos Eduardo Nogueira avatar
    15 posts
    Member since:
    Jul 2009

    Posted 10 Sep 2009 Link to this post

    Ok.
    I read your suggestions and changed the html code for both cases but, the problem is the same, even if I remove the panel object.
    Did you do something like this in some application, that is, work with ajax, grid and label and get the result as you expect?
  9. Answer
    ManniAT
    ManniAT avatar
    877 posts
    Member since:
    Nov 2003

    Posted 10 Sep 2009 Link to this post

    Hi,

    yes - I did it's not really uncommon to have "message controls" on a page.
    Is it possible, that your TR / label is inside another "server driven" control?

    Just to ensure if i basically works - could you place (only for testing) your label "outside anything" (same level as the grid) directly on the page?

    Regards
    Manfred
  10. Carlos Eduardo Nogueira
    Carlos Eduardo Nogueira avatar
    15 posts
    Member since:
    Jul 2009

    Posted 10 Sep 2009 Link to this post

    Hi Manfred,

    Great!
    After your last post, I could show the message in a label. The problem was the code behind, rsrs... Besides the DeleteCommand() method, I have ItemCreated() and NeedDataSource() methods of radgrid, and in these methods became the property visible of label to false if it's works correctly.

    Thank you very much! I will mark the last post as the answer!

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