Instead of placing controls on an .aspx page, I tend to create them in a C# class. For me, this architecture not only facilitates code reuse, but makes complex web applications easy to manage. One aspect of this architecture that is always problematic is event handling. My latest project was no exception. Its really a memory issue. That is my memory. Like I can’t remember from project to project the correct C# syntax.
The answer is really simple. Lets say you have a control with an ID of "ConcelNewRecord". When clicked, you want to cancel a pending action. Just code the control "Click" property as follows;
CancelNewRecord.Click += new EventHandler(this.CancelNewRecord_Click);
You will also need to code the event actions, e.g.;
protected void CancelNewRecord_Click(object sender, EventArgs e)
{
LinkButton lb = (LinkButton)sender;
Panel Panel1 = (Panel) lb.Parent.Parent.Parent.Parent;
Panel1.Visible = false;
lb = (LinkButton)Panel1.FindControl("NewRecord");
if(lb != null)
lb.Visible = true;
}
The above code is encapsulated in a class that is instantiated from an aspx.cs page.
Very useful information. Me too have some problem with syntax. I am so much confused while developing the application so willing to get all known on mind.
LikeLike
Amazing information. I was worried about the javascript onclick event. OnClick Event are sometime must be occurred by dynamics.
LikeLike