![](/img/trans.png)
[英]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.