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

Sys.WebForms.PageRequestManagerServerErrorException with sorted columns

8 Answers 209 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Steve
Top achievements
Rank 1
Steve asked on 31 Aug 2010, 09:44 PM
Hello,

Our website uses RadGrids that are created entirely in code-behind, because each grid's columns are controllable by the user.  The user is allowed to add and remove columns as well as move columns around.  I used the following articles as the basis for the page architecture:

http://www.telerik.com/help/aspnet-ajax/grdprogrammaticcreation.html
http://www.telerik.com/help/aspnet-ajax/grdchanginggridstructuredynamically.html

The grid is created dynamically, and added to a placeholder control that is defined on the page.  In addition, the columns are created dynamically, in the OnInit method of the page.

As a side note:  In the first article referenced above, it states that if you are creating the grid entirely in code-behind: "No ViewState is required for grid structure to be persisted as it is recreated on each page initialization".  However, this is not entirely true, because if you allow sorting, and if viewstate is disabled, you cannot click on the sort icon to affect a sort.

Regardless of whether the grid's viewstate is enabled or not, the problem arises when I sort a column, and then delete the sorted column.  When I delete the sorted column, I get the following error:

Sys.WebForms.PageRequestManagerServerErrorException: An error has occurred because a control with id 'ctl00$ContentPlaceHolderMain$ItemView1$grid1$ctl00$ctl02$ctl01$ctl09' could not be located or a different control is assigned to the same ID after postback. If the ID is not assigned, explicitly set the ID property of controls that raise postback events to avoid this error.

The id of the offending control might be different each time, but when I look at the HTML, it always corresponds to the <input type="image"> tag that represents the sort icon (the up/down arrow).  This input tag has a name attribute that matches the control name in the error message, but it has no ID attribute.  I don't know if this is the reason for the error or not.  I also get the above error when adding a column, and moving that column to a position to the left of the sorted column.

In any case, I am having a difficult time creating a small test project that duplicates the behavior.  In the meantime, I was wondering if Telerik or anybody has encountered this problem and hopefully found a solution.

Thanks for any help!
Steve

8 Answers, 1 is accepted

Sort by
0
Pavlina
Telerik team
answered on 06 Sep 2010, 10:16 AM
Hello Steve,

Have in mind that if you change the columns on Page.Init (this is where you create your grid control) and create different set of columns, on next phase when ViewState get restored (by the Page pipeline) this will probably cause the issue.

You can try setting EnableViewState to false of RadGrid control and EnableColumnViewState to false of any GridTableView as well.

Please give this suggestion a try.

All the best,
Pavlina
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Steve
Top achievements
Rank 1
answered on 09 Sep 2010, 08:57 PM
Thanks for the reply.  As I have stated before, it does not matter if the RadGrid's EnableViewState property is true or false.  I get the error either way.  In any case, I need to have EnableViewState set to true, otherwise clicking on the existing sort icon does nothing, and I have a requirement that says I must be able to click on the sort icon to toggle the sort direction.

I also have the RadGrid's MasterTableView's EnableColumnViewState set to false.  I learned that it must be false if you expect to add or delete columns from the grid.  I have no other GridTableView's as this is a flat, single-layer grid.

You mention that "on next phase when ViewState get restored (by the Page pipeline) this will probably cause the issue."  Can you tell me in what method the viewstate is restored?

Thank you.
0
Pavlina
Telerik team
answered on 10 Sep 2010, 02:36 PM
Hi Steve,

Are you able to reproduce the issue in a sample page? We will appreciate if you could send it via a support ticket so that we can investigate it locally and provide resolution.

Thank you.

Sincerely yours,
Pavlina
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Steve
Top achievements
Rank 1
answered on 10 Sep 2010, 02:54 PM
At this time, I am unable to reproduce the issue in a simple project.  Unfortunately, I have to put this issue on low priority in favor of higher priority projects.  My workaround at this time is to capture the RadGrid's ItemCreated event, and change the sort icon from a <input> tag to a <image> tag, thereby disabling the sort capability using the icon.  The user can still sort by clicking on the header text.  Doing this eliminates the error when I delete the sorted column from the grid.

If and when I get the time, I will attempt to reproduce the error in a simple project.  If I can, I will open a support ticket.

Thanks.
0
Pavlina
Telerik team
answered on 10 Sep 2010, 03:21 PM
Hi Steve,

I am glad you found a workaround for the moment. However, if you need further assistance I will be waiting for your sample project.

Greetings,
Pavlina
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Alex Galie
Top achievements
Rank 2
answered on 09 Nov 2012, 09:34 AM
Hi,

Well it's two years later, but I ran into the same problem, I was wondering if you could help me apply the same workaround :)

How exactly are you changing <input> to <img> in the ItemCreated event?


Thanks,
Alex
0
Steve
Top achievements
Rank 1
answered on 09 Nov 2012, 12:08 PM
Alex,

In the code below, this.Grid is our RadGrid.

            this.Grid.ItemCreated += new GridItemEventHandler(Grid_ItemCreated);<br><div></div>

later:

private void Grid_ItemCreated(object sender, GridItemEventArgs e)
{
    if (e.Item is GridHeaderItem)
    {
        // get the sorted gridcolumn
        if (e.Item.OwnerTableView.SortExpressions.Count > 0)
        {
            GridColumn sortedGridColumn = e.Item.OwnerTableView.GetColumnSafe(e.Item.OwnerTableView.SortExpressions[0].FieldName);
            if (sortedGridColumn != null)
            {
                // find the table cell that has the sort icon.
                foreach (TableCell cell in e.Item.Cells)
                {
                    // look for the GridImageButton representing the sort icon.
                    foreach (Control ctrl in cell.Controls)
                    {
                        if (ctrl is GridImageButton)
                        {
                            // We assume that a GridImageButton will only be present on the sorted column, and the GridImageButton is the sort icon.
                            cell.Controls.Remove(ctrl);
                            System.Web.UI.WebControls.Image img = new System.Web.UI.WebControls.Image();
                            img.ImageUrl = WebUtils.ResolveUrl(
                                e.Item.OwnerTableView.SortExpressions[0].SortOrder == GridSortOrder.Ascending
                                ? sortedGridColumn.SortAscImageUrl : sortedGridColumn.SortDescImageUrl);
                            cell.Controls.Add(img);
                            return;
                                }
                    
}
                }
            }
        }
    }
}

The WebUtils.ResolveUrl is just a helper method we created to convert URL that contain a tilde into a relative URL:

/// <summary>
/// Returns a site relative HTTP path from a partial path starting out with a ~.
/// Same syntax that ASP.Net internally supports but this method can be used
/// outside of the Page framework.
///
/// Works like Control.ResolveUrl including support for ~ syntax
/// but returns an absolute URL.
/// </summary>
/// <param name="originalUrl">Any Url including those starting with ~</param>
/// <returns>relative url</returns>
public static string ResolveUrl(string originalUrl)
{
    if (originalUrl == null)
        return null;
 
    // *** Absolute path - just return   
    if (originalUrl.IndexOf("://") != -1)
        return originalUrl;
 
    // *** Fix up image path for ~ root app dir directory
    if (originalUrl.StartsWith("~"))
    {
        string newUrl = "";
        if (HttpContext.Current != null)
            newUrl = string.Concat(HttpContext.Current.Request.ApplicationPath, originalUrl.Substring(1)).Replace("//", "/");
        else
            // *** Not context: assume current directory is the base directory
            throw new ArgumentException("Invalid URL: Relative URL not allowed.");
 
        // *** Just to be sure fix up any double slashes
        return newUrl;
    }
    return originalUrl;
}

Frankly, I don't remember if the ResolveUrl call is necessary in this case, but it doesn't hurt.

I hope this helps.
Steve
0
Alex Galie
Top achievements
Rank 2
answered on 12 Nov 2012, 06:35 AM
Thanks, that helped a bunch!
Tags
Grid
Asked by
Steve
Top achievements
Rank 1
Answers by
Pavlina
Telerik team
Steve
Top achievements
Rank 1
Alex Galie
Top achievements
Rank 2
Share this question
or