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
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