[英]How to call parent UserControl method from a child UserControl in asp.net?
[英]How to Call a Parent Method from UserControl in asp.net?
我有一个ASP.NET Page
,其中包含一个购物车 UserControl
。 现在,当用户Click
UserControl
CheckoutButton
,我想将他重定向到一个页面,当CustomerID会话为null
时,将在该页面输入客户信息。
在UserControl中:
protected void lnkCheckOut_Click1(object sender, EventArgs e)
{
if (Session["SalesCustomerID"] != null)
{
//CompleteOrder();
}
else
{
//Call here method of Parent Page
}
}
在Product.aspx.cs中
在Product.aspx
页中,存在UserControl
。 此页面还包含MasterPage
。
public void CallCustomerForm()
{
//show/redirect to customer entry form
}
那么,如何asp.net using c#?
从UserControl
按钮单击asp.net using c#?
调用ParentControl
的方法asp.net using c#?
我认为您应该停下来思考一下您的设计。 您的控件永远不需要知道包含它们的页面的任何信息-您需要从另一个控件中找到页面上的控件这一事实告诉我,您应该重新考虑问题。
我能告诉您的最好的事情(我对您的体系结构了解得很少)是,您应该将对控件的引用传递给希望在用户控件中找到的控件。 这样,您的控件就不必了解自身外部的内容。
之前已经回答过类似的问题。
此处: http : //www.codeproject.com/Articles/28503/Transfering-control-to-Page-ASPX-from-Control-ASCX
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.