I have a HiddenField
on my master page, and its value is set in Page_Load
event of the master page. In one of my content pages, I need this value in Page_Load
event. So I added <%@ MasterType VirtualPath="~/Site.Master"%>
to my content page, and created a property in the master page to read the hidden field's value. But, the Page_Load
events seem to be fired in reverse order, that is, first the content page, and then the master page, because my property is always an empty string. Here's the code for my property read
method and Page_Load
event.
Site = public partial class(System.Web.UI.MasterPage)
protected
method Page_Load(sender : object; e : EventArgs);
private
method GetCurrentCenter: String;
public
property CurrentCenter: String read GetCurrentCenter;
end;
method Site.Page_Load(sender : object; e : EventArgs);
begin
hfCurrentCenter.Value := '1';
end;
method Site.GetCurrentCenter: String;
begin
Result := hfCurrentCenter.Value;
end;
And here's the Page_Load
event in my content page:
method ContentPage.Page_Load(sender : object; e : EventArgs);
var
Center: DropDownList;
begin
if Master.CurrentCenter <> '-1' then // --< Master.CurrentCenter is always an empty string
begin
Center := DropDownList(cuWizard.CreateUserStep.ContentTemplateContainer.FindControl("Center"));
Center.Enabled := False;
end;
end;
Why is CurrentCenter
always an empty string?
I think your problem is related to page lifecycle. if you look at the order of firing of init and load events then you might get your answer.
INIT_EVENTS:
INIT_usercontrols
INIT_MasterPage
INIT_Page
LOAD Events:
Load :Page
Load: MasterPage
Load: UserControl