【问题标题】:How to retain content page controls' viewstate when changing master page?更改母版页时如何保留内容页控件的视图状态?
【发布时间】:2013-01-20 07:27:35
【问题描述】:

我在 Global.asax 中使用此代码更改母版页:

method Global.Application_PreRequestHandlerExecute(src: System.Object; e: EventArgs);
begin
  var p: System.Web.UI.Page := System.Web.UI.Page(self.Context.Handler);
  if p <> nil then
    p.PreInit += new EventHandler(page_PreInit)
end;

method Global.page_PreInit(sender: System.Object; e: EventArgs);
var
  S: String;
begin
  var p: System.Web.UI.Page := System.Web.UI.Page(self.Context.Handler);
  if p <> nil then
    if p.Master <> nil then
    begin
      if Request.Params['__EVENTTARGET'] <> nil then
      begin
        S := Request.Params['__EVENTTARGET'];
        if S.Length > 0 then
          S := S.Substring(S.IndexOf('$') + 1);
        if S = 'lbPrint' then
          Session['P'] := '1'
        else if S = 'lbNormal' then
          Session['P'] := '0';

        if Session['P'].ToString = '1' then
          S := '/Print.Master'
        else
          S := '/Site.Master';
        if not p.MasterPageFile.ToUpper.Equals(S.ToUpper) then
          p.MasterPageFile := S;
      end;
    end;
end;

每当更改母版页时,内容页中所有控件的视图状态都会丢失。我想知道如何保存它们...

【问题讨论】:

    标签: asp.net delphi-prism oxygene


    【解决方案1】:

    更改母版页确实会影响生成的控制结构。 因此 ASP.NET 无法加载视图状态,因为它使用控件索引来执行此操作。

    我不知道您使用的是哪个版本的 .NET,但也许有解决方案。

    你试过ViewStateModeByIdAttribute吗?

    您可能需要一个使用此属性的自定义容器控件,它是INamingContainer 的实现。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-08-02
      • 1970-01-01
      • 1970-01-01
      • 2013-05-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多