HttpException Creating Control Outside Web Part

Last post 11-13-2009 2:29 PM by squebler. 3 replies.

Sort Posts:

  • HttpException Creating Control Outside Web Part

    11-05-2009, 3:51 PM
    • Member
      point Member
    • squebler
    • Member since 10-06-2009, 5:40 PM
    • Posts 7

    I am getting an HttpException stating:

    An error has occurred because a control with id 'ctl00$m$g_68955b2d_44ee_4f9e_a611_9a1b02fe9af3$ctl00$ASPxGridView2$ctl00$DXEditor2$DDD$ctl15$ctl05' 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.

    This error does not occur if I use this original code:

    docList2 = new ASPxGridView(); 
    docList2.ID = "ASPxGridView2"; 
    
    GridViewDataColumn id = new GridViewDataColumn { FieldName = "ID" };
    GridViewDataTextColumn LinkFilename = new GridViewDataTextColumn { FieldName = "LinkFilename", Caption = "Filename" }; 
    GridViewDataTextColumn Created = new GridViewDataTextColumn { FieldName = "Created" }; 
    GridViewDataTextColumn Modified = new GridViewDataTextColumn { FieldName = "Modified" }; 
    
    docList2.Columns.Add(id); 
    docList2.Columns.Add(LinkFilename); 
    docList2.Columns.Add(Created); 
    docList2.Columns.Add(Modified); 
    
    docList2.SettingsBehavior.AllowFocusedRow = true; 
    docList2.Visible = true; 
    docList2.EnableRowsCache = true; 
    docList2.KeyFieldName = "ID"; 
    
    dodocList2GridBinding(); 
    docList2.Width = Unit.Percentage(100); 
    table.Rows[8].Cells[2].Controls.Add(docList2);


     

    But I moved part of the original code to a method in a class outside of the web part:

    public static ASPxGridView GenerateASPxGridViewFileSelector(string ID) 
    { 
    	ASPxGridView grdAsmList = new ASPxGridView(); 
    	grdAsmList.ID = ID; 
    	grdAsmList.SettingsBehavior.AllowFocusedRow = true; 
    	grdAsmList.Visible = false; 
    	grdAsmList.EnableRowsCache = true; 
    	grdAsmList.KeyFieldName = "ID"; 
    	grdAsmList.Width = Unit.Percentage(100); 
    
    	// assembly grid view columns GridViewDataColumn colId = new GridViewDataColumn { FieldName = "ID" }; 
    	grdAsmList.Columns.Add(colId); 
    	GridViewDataColumn colLinkFilename = new GridViewDataColumn { FieldName = "LinkFilename", Caption = "Filename" }; 
    	grdAsmList.Columns.Add(colLinkFilename); 
    	GridViewDataColumn colCreated = new GridViewDataColumn { FieldName = "Created" }; 
    	grdAsmList.Columns.Add(colCreated); 
    	GridViewDataColumn colModified = new GridViewDataColumn { FieldName = "Modified" }; 
    	grdAsmList.Columns.Add(colModified); return grdAsmList; 
    }


     

    Then I changed the original web part code to use this new method, and this now I am getting the above HttpException.

    docList2 = ArrowUtils.GenerateASPxGridViewFileSelector("ASPxGridView2");
    dodocList2GridBinding();
    docList2.Width = Unit.Percentage(100);
    table.Rows[8].Cells[2].Controls.Add(docList2);


     

    I do not understand why this error is happening.  It seems to me that I am doing the exact same thing as before, the only difference is that I am now creating the new instance in a different class.

    Can someone explain to me what is going on? 

     

     

    Filed under: ,
  • Re: HttpException Creating Control Outside Web Part

    11-10-2009, 10:54 PM

    Hi,

    As we know, any control in the ASP.NET webpage will have an unique ID property.

    Let's try the two tips below.

    1, If we had set  the EnableViewsSate property of the page or the control "False", then set it back to "True".

    2, Try to set an unique ID property for all the controls, include controls in cells.

    If it doesn't work, could you please paste the code of "ASPxGridView" class here for us to talk about it more details.

     

    Hope it helps.
    I'm always ready for your reply.

    Thank you for thinking of ASP.NET Forums,
    Jerry Weng - MSFT

    If the post helps you, please click the Mark As Answer or the Mark As Not Answer if not.
  • Re: HttpException Creating Control Outside Web Part

    11-13-2009, 2:23 PM
    • Member
      point Member
    • squebler
    • Member since 10-06-2009, 5:40 PM
    • Posts 7

    I checked your EnableViewState tip, and that's ok.

    I checked on the unique ID, but unfortunately the GridViewDataColumns don't have an ID property.

    ASPxGridView and GridViewDataColumns are DevExpress controls, so I don't have the code.  I think I may just not be able to use the DevExpress controls for this.

    Thanks for your help!

  • Re: HttpException Creating Control Outside Web Part

    11-13-2009, 2:29 PM
    • Member
      point Member
    • squebler
    • Member since 10-06-2009, 5:40 PM
    • Posts 7

    By the way, something I discovered is that this works in a different web part of mine, but I'm not sure why.

    In the web part where this does work, the ASPxGridView is being added to a Table control.  That Table control is being added to a custom control that inherits Control.  The custom control is then added to the web part's controls.

    In the web part where this does not work, the ASPxGridView is being added to a Table control, and the Table control is being added directly to the web part's controls.

    Aside from that, I don't see any major differences.

Page 1 of 1 (4 items)