Infragistics Home

Infragistics Forums

Infragistics community online discussions.
Welcome to Infragistics Forums Sign in | FAQ
in Search

Creating WebPanel dynamically through code

Last post 07-30-2008 15:43 by [Infragistics] Rumen Stankov. 4 replies.
Page 1 of 1 (5 items)
Sort Posts: Previous Next
  • 07-30-2008 11:37

    • icscare
    • Not Ranked
    • Joined on 05-23-2008
    • Points 105

    Creating WebPanel dynamically through code

    I am trying to create a WebPanel dynamically through code, but when I do, it does not pick up the header background image or any of the javascript for collapsing.  I can set the ImageDirectory to get the image, but not the JavaScriptFileName.

    Here is an example:

    Infragistics.WebUI.Misc.WebPanel pnlNew = new Infragistics.WebUI.Misc.WebPanel();
    pnlNew.Header.Text = "Test panel";
    pnlNew.Expanded = false;
    // Create another control (e.g. UltraWebGrid) dynamically here
    pnlNew.Controls.Add(gridNew);
    // Add dynamically-created WebPanel to an existing ASP.net panel on the page
    this.pnlMain.Controls.Add(pnlNew);

    The panel is placed on the page correctly with its contents, but the header is not clickable and cannot expand/collapse.

    Any help would be appreciated.  Thank you.

    • Post Points: 5
  • 07-30-2008 12:48 In reply to

    • icscare
    • Not Ranked
    • Joined on 05-23-2008
    • Points 105

    Re: Creating WebPanel dynamically through code

    I also get JavaScript errors on line 136 of the ig_webpanel.js file (retrieved by ScriptResource.axd) that read: "elem is null"

    Line 136 is:  var style = elem.currentStyle;

    In this function:

    	    ig_WebPanel.prototype._getCurrentStyle=function(elem)
    	                                            {
    	                                                var style = elem.currentStyle;
                                                        if(style == null)
                                                        {
                                                            var w = document.defaultView;	
                                                            if(w == null)
    	                                                        w = window;
                                                            if(w.getComputedStyle)
    	                                                        style = w.getComputedStyle(elem, '');
                                                        }
                                                        return style;
    	                                            }
    

    So it looks like the javascript doesn't know how to get the element from the page.

    Any ideas?

    • Post Points: 20
  • 07-30-2008 13:07 In reply to

    Re: Creating WebPanel dynamically through code

    Hello,

    Yes, I believe I know what is going on. If you create a control dynamically, you will also need to explicitly set its ID - otherwise it will not generate a valid javascript identified and various javascript errors might occur.

    So please add the following line:

    panel.ID = "Panel1";

    and this will hopefully resolve the problem.

    Please, let me know if this helps. 

    Best Regards,
    Rumen Stankov (MCSD.NET)
    The Infragistics ASP.NET Team
    • Post Points: 20
  • 07-30-2008 15:28 In reply to

    • icscare
    • Not Ranked
    • Joined on 05-23-2008
    • Points 105

    Re: Creating WebPanel dynamically through code

    That worked great.  I was doing that previously, appending a GUID to "pnlNew" as an identifier, but it was causing an error message:

    Error: missing ; before statement
    Source File: http://mypc/test.aspx
    Line: 287, Column: 5
    Source Code:
     var octl00xmainxpnlNew17bea5bf-2d5c-4f86-a9af-244bb5cc880axctl00 = igtbl_initGrid("ctl00xmainxpnlNew17bea5bf-2d5c-4f86-a9af-244bb5cc880axctl00",[false,0,2,1,2,2,"ig_29b29929_r1","",2,3,"",1,"","",0,"ig_29b29929_r4",1,22,"","ig_29b29929_r7","","","","",1,

    I guess the ID was too long or something.

    Thank you for your help.

    • Post Points: 20
  • 07-30-2008 15:43 In reply to

    Re: Creating WebPanel dynamically through code

    Cool. Glad I was able to help.

    The  reason you had javascript errors for GUIDs is that the "-" character is not a valid identifier in Javascript, so you cannot name a variable with that. If you do wish to use GUIDs for IDs, you can probably relplace "-" with underscores "_", that should probably address the issue.


    Best Regards,
    Rumen Stankov (MCSD.NET)
    The Infragistics ASP.NET Team
    • Post Points: 5
Page 1 of 1 (5 items)
Powered by Community Server (Commercial Edition), by Telligent Systems