samedi 31 mai 2014

Below code is not working,pls suggest


Vote count:

0




I have a small user control having a textbox and a button in it. I have a label in my page which consuming the usercontrol,on button click event of user control I am finding out the area of user input value and want to display that area in lebel in main page.



public partial class WebUserControl1 : System.Web.UI.UserControl
{
public delegate void myeventhandler(object sender,MyEventArgs e);

public event myeventhandler MyEvent;

protected void Button1_Click(object sender, EventArgs e)
{
int radious= Convert.ToInt32(TextBox1.Text);
double area = 3.14 * radious * radious;
MyEventArgs myeventargs = new MyEventArgs();
myeventargs.Area = area;
MyEvent(this, myeventargs);

}

}
public class MyEventArgs : EventArgs
{
public double Area { set; get; }

}


in the main page I have written the below code:



public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
WebUserControl1 objuc = new WebUserControl1();
objuc.MyEvent += new WebUserControl1.myeventhandler(DisplayArea);

}

public void DisplayArea(object sender,MyEventArgs e)
{
Label1.Text = e.Area.ToString();

}
}

But I am getting a NullReferenceError on line
MyEvent(this, myeventargs);


any help would be appreciated



asked 26 secs ago






Aucun commentaire:

Enregistrer un commentaire