I am trying to separate all DB calls required by ASCX.cs to call only from ASPX.cs, I am trying it with delegate and events.
my ASCX.cs has
namespace x.xx.xy.xyy.xyyy
{
public partial class PaymentItem : UserControlBase
{
public delegate void Handler(Dictionary<string, string> keyvalues);
public event Handler aPICall;
}
}
my ASPX.cs has
namespace x.xx.xz.xzz.xzzz
{
public partial class PaymentItemPopUp
{
protected global::x.xx.xy.xyy.xyyy.PaymentItem ucPaymentItem;
protected void Page_Load(object sender, EventArgs e)
{
this.ucPaymentItem.aPICall += new PaymentItem.Handler(ServiceAPICAll);
}
protected void ServiceAPICAll(Dictionary<string, string> keyvalues){
}
}
}
I am getting ‘Object reference not set to an instance of an object’ when compiler hits the following line
this.ucPaymentItem.aPICall += new PaymentItem.Handler(ServiceAPICAll);
I suppose the issue from the following line
protected global::x.xx.xy.xyy.xyyy.PaymentItem ucPaymentItem;
any idea?
It works now.
I removed designer generated code for my user control in my aspx page
my ASPX.designer.cs
Then I changed like the following
my ASPx.cs
My ASPX