Reference Controls on MasterPage

C

clintonG

// MasterPage
<LinkButton1 />
<Panel1>
<LinkButton2 />
</Panel1>

LinkButtons defined in the MasterPage are being used to simulate tabbed
navigation. When LinkButton1 is clicked, the 'tab' sets Panel1.Visible =
"true" and changes the background color properties of the tab by setting the
LinkButton1.CssClass property. LinkButton2 is then displayed. A content page
is loaded when LinkButton2 is clicked.

When LinkButton2 is clicked -- POOF -- it disappears from the View State and
LinkButton1.CssClass loses background color state so the 'tab' does not
appear as if it had ever been selected.

I've tried strongly typed MasterPage directives with public properties and
I've tried using the FindControl method but could not restore state to
either control. The ViewState remains empty.

Then I learned about the PostBackUrl property which the LinkButton supports
and which is supposed to allow the properties of a control to be passed to
the new content page where we can get or set properties of the control using
a PreviousPage object.

But nooooooo. Not for me.

PreviousPage [1] can get the ID of LinkButton2 and LinkButton2 is now in the
ViewState but is has no Render Size values and I can not get or set any
other properties on LinkButton2; i.e. setting neither the Enabled nor the
Visible property or both will not redisplay the LinktButton2 control as the
Render State value remains 0 (the control is not being rendered as HTML).

I can't even restore the background color state to the LinkButton1 tab [2].

I have two question to ask:

A.) Does anybody have a clue what to do? How do controls disappear from the
ViewState?

B.) Does anybody know how to find a child control such as LinkButton2 when
not using PostBackUrl?

<%= Clinton Gallagher
METROmilwaukee (sm) "A Regional Information Service"
NET csgallagher AT metromilwaukee.com
URL http://metromilwaukee.com/
URL http://clintongallagher.metromilwaukee.com/

[1]
LinkButton tab1 = PreviousPage.Master.FindControl("HeaderTab1") as
LinkButton;
if(tab1 != null)
tab1.CssClass = "HeaderTab";
 
B

Brock Allen

I'm not exactly sure what the issue is, but as a side note in 2.0 there's
a MultiView control that would do the job of your Panel. Controls inside
the MultiView maintain their ViewState across postbacks.
 
C

clintonG

Thanks for bringin that to my attention. I'll certainly study the use of the
MultiView control but having any controls removed from the viewstate still
has me baffled and apparently everybody else.

So, it would still be very helpful if you could respond to the question
regarding how to reference child controls when using MasterPages which for
me remains a task I have not figured out how to accomplish.

Lots of references have been published when the control is a child of the
page itself. Literally nothingI have been able to discover when the control
is a child of another control in the page such as when using a panel control
and most certainly when using a MultiView control.

Please take some time to write a tutorial about this issue as there are
apparently several methodologies none of which I have been able to 'master'
no pun intended.

<%= Clinton Gallagher

Brock Allen said:
I'm not exactly sure what the issue is, but as a side note in 2.0 there's
a MultiView control that would do the job of your Panel. Controls inside
the MultiView maintain their ViewState across postbacks.




// MasterPage
<LinkButton1 />
<Panel1>
<LinkButton2 />
</Panel1>
LinkButtons defined in the MasterPage are being used to simulate
tabbed navigation. When LinkButton1 is clicked, the 'tab' sets
Panel1.Visible = "true" and changes the background color properties of
the tab by setting the LinkButton1.CssClass property. LinkButton2 is
then displayed. A content page is loaded when LinkButton2 is clicked.

When LinkButton2 is clicked -- POOF -- it disappears from the View
State and LinkButton1.CssClass loses background color state so the
'tab' does not appear as if it had ever been selected.

I've tried strongly typed MasterPage directives with public properties
and I've tried using the FindControl method but could not restore
state to either control. The ViewState remains empty.

Then I learned about the PostBackUrl property which the LinkButton
supports and which is supposed to allow the properties of a control to
be passed to the new content page where we can get or set properties
of the control using a PreviousPage object.

But nooooooo. Not for me.

PreviousPage [1] can get the ID of LinkButton2 and LinkButton2 is now
in the ViewState but is has no Render Size values and I can not get or
set any other properties on LinkButton2; i.e. setting neither the
Enabled nor the Visible property or both will not redisplay the
LinktButton2 control as the Render State value remains 0 (the control
is not being rendered as HTML).

I can't even restore the background color state to the LinkButton1 tab
[2].

I have two question to ask:

A.) Does anybody have a clue what to do? How do controls disappear
from the ViewState?

B.) Does anybody know how to find a child control such as LinkButton2
when not using PostBackUrl?

<%= Clinton Gallagher
METROmilwaukee (sm) "A Regional Information Service"
NET csgallagher AT metromilwaukee.com
URL http://metromilwaukee.com/
URL http://clintongallagher.metromilwaukee.com/
[1]
LinkButton tab1 = PreviousPage.Master.FindControl("HeaderTab1") as
LinkButton;
if(tab1 != null)
tab1.CssClass = "HeaderTab";
 

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,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top