उपयोगकर्ता नियंत्रण में एक प्रतिनिधि बनाएं और फिर उसे अपने जनक पृष्ठ से एक विधि निर्दिष्ट करते हैं।
class MyUserControl : UserControl
{
delegate object MyDelegate(object arg1, object arg2, object argN);
public MyDelegate MyPageMethod;
public void InvokeDelegate(object arg1, object arg2, object argN)
{
if(MyDelegate != null)
MyDelegate(arg1, arg2, argN); //Or you can leave it without the check
//so it can throw an exception at you.
}
}
class MyPageUsingControl : Page
{
protected void Page_Load(object sender, EventArgs e)
{
if(!Page.IsPostBack)
MyUserContorlInstance.MyPageMethod = PageMethod;
}
public object PageMethod(object arg1, object arg2, object argN)
{
//The actions I want
}
}
संदर्भ को स्टोर करने की कोई आवश्यकता नहीं है- प्रत्येक उपयोगकर्ता नियंत्रण पहले से ही एक पृष्ठ संपत्ति का खुलासा करता है। –