Sign In| Join
Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post May 03, 2012 06:17 AM by ericyzhou
Member
2 Points
23 Posts
May 02, 2012 08:23 AM|LINK
Create a customized template control:
public class TestViewStateControl: WebControl { [PersistenceMode(PersistenceMode.InnerProperty)] public ITemplate ContentTemplate { get; set;} protected override void CreateChildControls() { if ( ContentTemplate != null) { WebControl container = new WebControl(HtmlTextWriterTag.Div); ContentTemplate.InstantiateIn(container); Controls.Add(container); } base.CreateChildControls(); } }
Then add this control to page:
<custom:TestViewStateControl ID="testViewState" runat="server" EnableViewState="true" BackColor="Aquamarine" Height="100px" Width="200px"> <ContentTemplate> <asp:Button ID="btnHideParent" runat="server" Text="Hide" OnClick="btnHideParent_Click" /> </ContentTemplate> </custom:TestViewStateControl>
The "bthHideParent_Click" method, set parent's Visibility property to false like this:
protected void btnHideParent_Click(object sender, EventArgs e) { testViewState.Visible = false; }
If you run this page, click the button will not causing the "testViewState" control to become invisible. Even if I turn off view state it is still not working as I expected
viewstate
May 03, 2012 06:17 AM|LINK
Did some more test, the child control seems can only making its parent control invisible when its parent's viewstate is turned off. Any comment guys?
ericyzhou
Member
2 Points
23 Posts
Why a child control can not change the visibility of its parent control?
May 02, 2012 08:23 AM|LINK
Create a customized template control:
public class TestViewStateControl: WebControl { [PersistenceMode(PersistenceMode.InnerProperty)] public ITemplate ContentTemplate { get; set;} protected override void CreateChildControls() { if ( ContentTemplate != null) { WebControl container = new WebControl(HtmlTextWriterTag.Div); ContentTemplate.InstantiateIn(container); Controls.Add(container); } base.CreateChildControls(); } }Then add this control to page:
The "bthHideParent_Click" method, set parent's Visibility property to false like this:
protected void btnHideParent_Click(object sender, EventArgs e) { testViewState.Visible = false; }If you run this page, click the button will not causing the "testViewState" control to become invisible. Even if I turn off view state it is still not working as I expected
viewstate
ericyzhou
Member
2 Points
23 Posts
Re: Why a child control can not change the visibility of its parent control?
May 03, 2012 06:17 AM|LINK
Did some more test, the child control seems can only making its parent control invisible when its parent's viewstate is turned off. Any comment guys?