在母版页呼叫用户控制方法从内容页 [英] Call User Control Method in Master Page from Content Page
本文介绍了在母版页呼叫用户控制方法从内容页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个自定义用户控件present在我的母版页加载网站JavaScript库到母版页的头部
I have a Custom User Control present in my master page that loads site-wide JavaScript libraries into the master page's head
像这样:
<html>
<head>
<CustomControl:MyScriptControl id="scripts" runat="server" />
</head>
<body>
<asp:ContententPlaceHolder id="pageContent" runat="server" />
</body>
</html>
我想有一个使用了母版调用用户控件的方法在网页的 MyScriptControl 这样基本上
public partial class ChildPage: System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
//// Invoke Method of MasterPage's UserControl: MyScriptControl
}
}
这可能吗?还是有更好的方法来做到这一点?
Is this possible ? Or is there a better way to do this ?
推荐答案
第1步:添加指令的MasterType在你的aspx页面
第2步:创建一个公共方法,在你的主页,这将调用你的用户控件的方法
。
第3步:从你的页面,您可以调用使用Master.Method该方法()
Step 1: Add a MasterType directive in your aspx page
Step 2: Create a public method in your master page which will call your usercontrol method.
Step 3: From your page you can call that method using Master.Method()
这篇关于在母版页呼叫用户控制方法从内容页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文