将用户控制方法调用到aspx页面(如果是aspx页面访问主页面) [英] call user control method into aspx page(if aspx page access master page)
问题描述
我有一个用户控件(名称为A.ascx)在这个用户控件中,一个方法是BindData(),
我想访问该方法Parantpage(名称为B.aspx),
非常简单:
像这样(在B.aspx的代码背后)
< b> A.BindData();
现在我的问题开始:
问题是mY B.aspx页面使用One Master页面(C.master),
所以如果我使用B.aspx页面的母版页,那么我无法调用这样的方法:
A.BindData(); 给出错误:
我该怎么办? ????
i查找类似的问题::
http://stackoverflow.com/questions/15019598/call-user-control-method-in-master-page-from-content -page [ ^ ]
此链接Give One解决方案,
但是这个解决方案不起作用是因为:
我的用户控件没有放在母版页然后我如何访问该用户控件方法at后面的母版页代码:
Plz帮助....
i have a User Control (name as A.ascx ) And in this user control one Method is BindData(),
I want to access that method to Parantpage (name as B.aspx),
which is very simple:
Like this (at code behind of B.aspx)
A.BindData();
Now My Problem Start:
Problem is mY B.aspx page use One Master page(C.master),
so if i use master page with B.aspx page then i am unable to call method like this:
A.BindData(); which give error:
so what can i do ????
i Find Similar prob at::
http://stackoverflow.com/questions/15019598/call-user-control-method-in-master-page-from-content-page[^]
This link Give One solution,
But this solution not work because:
my user control not place at master page then how i access That user control method at master page code behind:
Plz Help....
推荐答案
Hi
请在母版页的继承页面中设置如下指令,例如
Hi
please set below directive in inherited page from master page like
<%@ MasterType VirtualPath="~/Site.Master" %>
并在文件后面的继承页面代码中添加C#代码
and add C# code in inherited page code behind file
Master.callUsercontrolMethod();
以下是主页方法,它调用usercontrol的方法
below is master page method which call usercontrol's method
public void callUsercontrolMethod()
{
usercontrol.BindRepeater();
}
确实有效
it really works
这篇关于将用户控制方法调用到aspx页面(如果是aspx页面访问主页面)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!