Bug in ie webcontrol, tab.cs

M

mawi

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
 
M

mawi

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>
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,990
Messages
2,570,211
Members
46,796
Latest member
SteveBreed

Latest Threads

Top