Bug in ie webcontrol, tab.cs

Discussion in 'ASP .Net Web Controls' started by mawi, Jul 7, 2004.

  1. mawi

    mawi Guest

    Hello,

    I dont know if this a known bug but I found this one error
    in the "tab.cs" code for the tab class in the IE
    webcontrols package.

    The method WriteItemAttributes has this code (line 150):

    if (TargetID != String.Empty)
    {
    writer.WriteAttribute("targetID",
    Target.ClientID);
    }

    This causes a problem if at this point the pageviews have
    not been instantiated, or the like - ie the object is not
    yet ready. The first time the target is accessed, it will
    use the targetid property and get a reference to a control,
    at which time it is more probable it is ready.

    If one simply uses the property that is used in the check
    (TargetID) in the assignment the control works better, like so:

    if (TargetID != String.Empty)
    {
    writer.WriteAttribute("targetID", TargetID);
    }


    This yields no problems whatsoever afaics. Some notes:

    (1) This looks like it is unintentional, but it may be
    intentional and represent an implicit assumption that is
    not apparent from the code. But the check should be the
    same as used in the assignment, in my mind.

    (2) If intentional it is strange because the code will
    cause a null reference exception to be thrown when the
    pageview control has not yet been instantiated, the reason
    for which is very hard to see without the source (which is
    obviously the reason for me getting it and finding this).
    If intentional there should be some more descriptive message.


    With the bug fixed, dynamic tabs / pageviews works more as
    one would assume, without error.


    I could post a build with the bugfix somewhere, my own
    server is currently a little bit out of order. In order to
    build the webcontrols I recommend Peter Brombergs project
    (which I used) which makes fixing and building a snap. Find
    it at http://www.eggheadcafe.com/articles/20030426.asp.

    As soon as I have time I will post a project illustrating
    the problem, but here is a code excerpt:

    (the form has an empty tabstrip and multipage, one (server,
    asp) button "add tab" and one button "do roundtrip")

    The first mehtod is the addtab event handler:

    private void Button3_Click(object sender, System.EventArgs e)
    {
    String count = (TabStrip1.Items.Count + 1).ToString();
    PageView pv = CreatePageView( count );
    Tab t = CreateTab( count, pv.ID );
    MultiPage1.Controls.Add( pv );
    TabStrip1.Items.Add( t );
    }
    private void Page_Load(object sender, System.EventArgs e)
    {
    int pageCount = TabStrip1.Items.Count;
    if ( pageCount > 0 )
    for ( int i = 1; i <= pageCount; i++ )
    MultiPage1.Controls.Add( CreatePageView( i.ToString() ) );
    }
    private void DoRoundTrip(object sender, System.EventArgs
    e) { }
    private Tab CreateTab ( String count, String pageID )
    {
    Tab tempTab = new Tab();
    tempTab.ID = "dyn_tab_" + count;
    tempTab.Text = "Tab " + count;
    tempTab.TargetID = pageID;
    return tempTab;
    }
    private PageView CreatePageView ( String count )
    {
    PageView tempPage = new PageView();
    tempPage.EnableViewState = false;
    tempPage.ID = "page_" + count;
    Literal lit = new Literal();
    lit.Text = "<H1>Page for tab " + count + "</H1>";
    tempPage.Controls.Add( lit );
    return tempPage;
    }


    Without the bugfix, I get a null reference exception. With
    it, this works as expected.

    Maybe I have an old version, but I dont think so.

    Comments?


    Second; please help me out with how one best persists the
    child controls of a pageview, is there a simple way? Does
    not have to be recursive. Do I have to code the
    load/saveviewstate methods myself? Tips greatly
    appreciated. See post I made earlier today for more info on
    this issue. Thanks alot!


    /mawi
    m(yup, single m)(at)mawi(dot)org
     
    mawi, Jul 7, 2004
    #1
    1. Advertising

  2. mawi

    mawi Guest

    Bug in ie webcontrol, tab.cs - testpage

    Sample testpage, save as aspx file in a webroot, put
    "Microsoft.Web.UI.WebControls.dll" in "bin" directory of
    that root. Vanilla package will throw nullexception, with
    bugfix this works.

    //mawi

    <%@ Page language="c#" AutoEventWireup="true" %>
    <%@ Register TagPrefix="iewc"
    Namespace="Microsoft.Web.UI.WebControls"
    Assembly="Microsoft.Web.UI.WebControls" %>
    <script runat="server">
    void Page_Load()
    {
    for ( int i = 1; i <= TabStrip1.Items.Count; i++ )
    NewPV( i.ToString() );
    }
    private String NewPV( String count )
    {
    PageView pv = new PageView();
    pv.Controls.Add( new Literal() );
    ( pv.Controls[ 0 ] as Literal ).Text = "<H1>Page for tab
    " + count + "</H1>";
    MultiPage1.Controls.Add( pv );
    return (pv.ID = "page_" + count);
    }
    private void addTab(object sender, System.EventArgs e)
    {
    String count = (TabStrip1.Items.Count + 1).ToString();
    Tab t = new Tab();
    t.Text = t.ID = "Tab_" + count;
    t.TargetID = NewPV( count );
    TabStrip1.Items.Add( t );
    }
    </script>
    <html>
    <body>
    <form runat="server">
    <asp:button id="addBtn" runat="server" Text="+Tab"
    OnClick="addTab" />
    <iewc:tabstrip id="TabStrip1" runat="server"
    targetid="MultiPage1" />
    <iewc:multipage id="MultiPage1" runat="server" />
    </form>
    </body>
    </html>
     
    mawi, Jul 8, 2004
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Guest
    Replies:
    2
    Views:
    755
  2. Luis Ramírez.

    Can a webcontrol (webcontrol.dll) have a configuration file?

    Luis Ramírez., Jul 5, 2004, in forum: ASP .Net Building Controls
    Replies:
    2
    Views:
    218
    Luis Ramírez
    Jul 6, 2004
  3. Kasabaarde Sumta

    WebControl inside of WebControl and attaching events

    Kasabaarde Sumta, Dec 13, 2004, in forum: ASP .Net Building Controls
    Replies:
    0
    Views:
    212
    Kasabaarde Sumta
    Dec 13, 2004
  4. Fabricio

    Custom webcontrol that references another webcontrol

    Fabricio, Sep 21, 2005, in forum: ASP .Net Building Controls
    Replies:
    0
    Views:
    201
    Fabricio
    Sep 21, 2005
  5. Peter Morris [Air Software Ltd]

    WebControl with non-WebControl property

    Peter Morris [Air Software Ltd], Dec 7, 2004, in forum: ASP .Net Web Controls
    Replies:
    1
    Views:
    148
    Peter Morris [Air Software Ltd]
    Dec 7, 2004
Loading...

Share This Page