problem displaying an error message

4 posts, 0 answers
  1. mww
    mww avatar
    257 posts
    Member since:
    Sep 2012

    Posted 27 Jul 2011 Link to this post

    I want to display an error message in the grid if some operation has failed  (update, delete, etc)
    Ive followed an example suggested in the forums, but it doesnt work

    protected void RadGridImages_NeedDataSource(object source, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
            {
                List<Business.Logic.BusinessObjects.ArtistImage> lst = new List<Business.Logic.BusinessObjects.ArtistImage>();
                int aid = -1;
                bool isOK = int.TryParse(this.HiddenArtistID.Value, out aid);
                if (isOK)
                {
                    lst = artistImageManager.Get(aid);
                    if (lst != null)
                    {
                        this.RadGridImages.DataSource = lst;
                    }
                    else
                    {
                        if (this.RadGridImages.DataSourceID == "")
                        {
                            this.RadGridImages.DataSource = new string[] { };
                        }
                    }
                }
                if (!string.IsNullOrEmpty(gridMessage))
                {
                    DisplayMessage(gridMessage);
                }
            }
            private void DisplayMessage(string text)
            {
                RadGridImages.Controls.Add(new LiteralControl(string.Format("<span style='color:red'>{0}</span>", text)));
            }

    gridMessage is supplied a value when something fails, I then rebind the grid

    there IS a value in gridMessage when the NeedDataSource is fired, but the error message never gets displayed.
    Anyone see what Im doing wrong here ?
  2. Maria Ilieva
    Admin
    Maria Ilieva avatar
    4017 posts

    Posted 02 Aug 2011 Link to this post

    Hello Mark,

    Possible appraoch for acheiving the required fucntionality is to add an error label in the EditForm in ItemDataBound event to show the message. For example:
    protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
    {
        if (e.Item is GridEditFormItem && e.Item.IsInEditMode && check)
        {
            GridEditFormItem item = (GridEditFormItem)e.Item;
            Label lbl = new Label();
            lbl.ID = "ErrorLabel";
            lbl.Text = "Error";
            lbl.ForeColor = System.Drawing.Color.Red;
            (item.FindControl("CancelButton").Parent).Controls.Add(lbl);
            check = false;
        }
    }
     
     
     
    protected void RadGrid1_ItemUpdated(object source, GridUpdatedEventArgs e)
    {
        GridEditFormItem item = (GridEditFormItem)e.Item;
        if (e.Exception != null)
        {
            e.KeepInEditMode = true;
            e.ExceptionHandled = true;
            check = true;
     
        }
    }


    Also note that an easy method to validate data in edit form is using validation control for the controls in edit form. Please take a look at the following demo and see if it helps.
    Grid / Flexible Server-side Validation

    I hope this helps.

    Kind regards,
    Maria Ilieva
    the Telerik team

    Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. mww
    mww avatar
    257 posts
    Member since:
    Sep 2012

    Posted 02 Aug 2011 Link to this post

    OK thanks for your help, but why wont the other suggested method work ?  this was a solution recommend by the support team

    RadGridImages.Controls.Add(new LiteralControl(string.Format("<span style='color:red'>{0}</span>", text)));


    also, data validation isnt really the issue here, its just a way of trapping any unforeseen problems (like a database update failure)
  5. Maria Ilieva
    Admin
    Maria Ilieva avatar
    4017 posts

    Posted 04 Aug 2011 Link to this post

    Hello,

    I'm not sure where the provided code you are trying to implement is suggested. Actually the proper approach is presented in the following online demo.

    Best wishes,
    Maria Ilieva
    the Telerik team

    Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

Back to Top