从用户控件调用父页面中的方法? [英] Calling a method in parent page from user control?
本文介绍了从用户控件调用父页面中的方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
从用户控件调用父页面中的方法?
我的usercontrol中有一个gridview ..在它的一行按行命令...我想要父页面代码隐藏中的调用方法?
((MyPageName)this.Page)。CustomMethod();
我用这种方式来做到这一点......但是我知道那个...我知道有问题是方式的类型///你可以建议我任何替代方案吗? /
Calling a method in parent page from user control?
I have a a gridview in my usercontrol .. on its rowcommand of one button ... i want to call method in parent page's codebehind?
((MyPageName)this.Page).CustomMethod();
I used this way to do that ... but wehn i google that .. i came to know that there is problem is with type of way /// can u suggest me any alternative ?/
推荐答案
我的解决方案是在用户控件中公开事件并从父级附加方法。
My solution for this would be to expose the event in the user control and attach a method from parent.
这个事情将在我完成的事件处理的帮助下完成我的下面的代码。
This thing will be done with the help of event handling that i have done i the folowing code.
GridView gv = (GridView)UserControl.FindControl("gridview1");
gv.RowCommand += new GridViewCommandEventHandler("name of the event you want to call from parent page");
您可以尝试
this.NamingContainer
而不是
this.Page
我会这样做:< br $>
and I would do it like this:
MyPageName objMyPageName = this.NamingContainer as MyPageName;
if(objMyPageName != null)
{
objMyPageName.CustomMethod();
}
这篇关于从用户控件调用父页面中的方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文