Yes and no. You can actually hook events in the code behind. Use visual studio you get a little help creating the handlers. So on page load to hook the click event to the button you would do:
ButtonObject.Click+=new EventHandler(Button2_Click
Now where the help comes in is after you type "+=" you press tab twice which auto generates the event handler.
Now the event handler is generated without an access modifier it's just:
void Button2_Click(object sender, EventArgs e)
{
throw new NotImplementedException();
}
no modifier means that it's private
You can keep it as is and remove the onclick part from the aspx page because the event handler hooks in the .cs file OR do what I do. Delete the line that hooks the event which is: "ButtonObject.Click+=new EventHandler(Button2_Click
protected void Button2_Click(object sender, EventArgs e)
{
throw new NotImplementedException();
}
and on the aspx have onclick="Button2_Click"
Yes it is more work in C# but there is some help. In a windows application this is even easier as you can look in the control's properties in the designer and double click the event you want.
Main Topics
Browse All Topics





by: sammy1971Posted on 2009-10-14 at 12:30:39ID: 25574177
You can either double click the control to generate the default event
or if you find the event name in the property window ", Right click on the control, click on properties,the property window will appear on the right, You will see a thunder icon" click the event to create it