English 中文(简体)
进入主页的密码参数
原标题:Pass string parameters to master page
  • 时间:2010-01-26 21:56:27
  •  标签:
  • c#
  • asp.net

I m using C# language Asp.net version 3.5 I have a masterpage and pages which they use master. I think there are three ways to implement my application with ability passing parameters between controller to pages.

First Way : I need to pass a string parameter from page to master how I can do that ?
I m going to pass a string parameter between page to master when controller request page and then page pass parameter to it s master.

Second way : Passing some string parameters from a controller class to master page at first (not to page and then page to it s master).

Third Way : Passing to another class or field that must be static and then master load it s value.

这是我表现良好和安全的最佳或可能方式。

最佳回答

如果你需要掌握一些可贵硕士或申请中任何其他页数的直观价值,你可以尝试协会的许多客户-邦管理之一。 该网络支持:

  • View state
  • Control state
  • Hidden fields
  • Cookies
  • Query strings

查阅,该网页详细论述如何利用其中每一种备选办法,并帮助你找到正确的选择:

问题回答

让我假定,你有一个名为MyMaster的主人,拥有一种公共方法“Foo”。 你们还有一页“我的Page”。

在我的Page公司,你可以利用主人财产检索主人的提法。 如果你提出这一提法,你可以把它称作“Foo”方法。

((MyMaster)myPage.Master).Foo("some string")

从本质上讲,只要你能够接触一页,你就可以永远接触主人。

如果你试图在服务器方面这样做,你就可以在主页上揭开财产。 然后,“儿童”一页可以查阅财产。 不动产。

例如:

public partial class MyMaster : MasterPage
{
    public string MyString { get; set; }
}

public partial class MyPage : Page  
{
    protected void Page_Load(object sender, EventArgs e)
    {
        ((MyMaster)(this.Master)).MyString = "some value";
    }
}




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Transaction handling with TransactionScope

I am implementing Transaction using TransactionScope with the help this MSDN article http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx I just want to confirm that is ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

Microsoft.Contracts namespace

For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts;?

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签