如何在内容页面中调用母版页方法但不从母版页继承

时间:2021-03-26 21:12:26

How to call master page method in content page but the content page is not inheritted from the master page. what i have to do to call the master page method in content page

如何在内容页面中调用母版页方法,但内容页面不是从母版页继承的。我要做什么来调用内容页面中的母版页方法

this is my Operation master page method public void RedirectPage(string url) {
ifrmMstr.Attributes.Add("src", url);
}

这是我的操作主页面方法public void RedirectPage(string url){ifrmMstr.Attributes.Add(“src”,url); }

And this is my content page and i am calling the function like this in the page load

这是我的内容页面,我在页面加载中调用这样的函数

Operation master = new Operation(); master.rpage("../Default.aspx");

操作master = new Operation(); master.rpage( “../ Default.aspx的”);

2 个解决方案

#1


Does this help?

这有帮助吗?

https://www.google.co.nz/#q=expose+control+from+master+page+to+content+page

"....To access the Master Page's methods or properties from a content page, reference the Master Page through the Page.Master property. This property returns an object of type MasterPage, so you'll need to explicitly cast it to the appropriate type before calling its methods or referencing its properties. Alternatively, you can set the @MasterType directive, which adds a property to the auto-generated ASP.NET code-behind class code named Master that is a strongly-typed reference to the specified Master Page...."

“....要从内容页面访问母版页的方法或属性,请通过Page.Master属性引用母版页。此属性返回MasterPage类型的对象,因此您需要将其明确地转换为适当的在调用其方法或引用其属性之前键入。或者,您可以设置@MasterType指令,该指令将属性添加到名为Master的自动生成的ASP.NET代码隐藏类代码,该代码是指定Master的强类型引用页....”

This will also be useful

这也很有用

How to control elements on a asp.net master page from child page

如何从子页面控制asp.net主页面上的元素

#2


You can change the Master page frame's source from content page by calling a master page's JavaScript function and doing it client side.

您可以通过调用母版页的JavaScript函数并在客户端执行来从内容页面更改母版页框架的源代码。

Add something like this in your content page method (vb.net):

在您的内容页面方法(vb.net)中添加这样的内容:

    Dim frameSourceMethod As String = String.Format("YourMethod('{0}');",frameSourcePath)
    ScriptManager.RegisterStartupScript(Me, Me.GetType(), "displdcccdsse4errnfokf", frameSourceMethod , True)   

#1


Does this help?

这有帮助吗?

https://www.google.co.nz/#q=expose+control+from+master+page+to+content+page

"....To access the Master Page's methods or properties from a content page, reference the Master Page through the Page.Master property. This property returns an object of type MasterPage, so you'll need to explicitly cast it to the appropriate type before calling its methods or referencing its properties. Alternatively, you can set the @MasterType directive, which adds a property to the auto-generated ASP.NET code-behind class code named Master that is a strongly-typed reference to the specified Master Page...."

“....要从内容页面访问母版页的方法或属性,请通过Page.Master属性引用母版页。此属性返回MasterPage类型的对象,因此您需要将其明确地转换为适当的在调用其方法或引用其属性之前键入。或者,您可以设置@MasterType指令,该指令将属性添加到名为Master的自动生成的ASP.NET代码隐藏类代码,该代码是指定Master的强类型引用页....”

This will also be useful

这也很有用

How to control elements on a asp.net master page from child page

如何从子页面控制asp.net主页面上的元素

#2


You can change the Master page frame's source from content page by calling a master page's JavaScript function and doing it client side.

您可以通过调用母版页的JavaScript函数并在客户端执行来从内容页面更改母版页框架的源代码。

Add something like this in your content page method (vb.net):

在您的内容页面方法(vb.net)中添加这样的内容:

    Dim frameSourceMethod As String = String.Format("YourMethod('{0}');",frameSourcePath)
    ScriptManager.RegisterStartupScript(Me, Me.GetType(), "displdcccdsse4errnfokf", frameSourceMethod , True)