<h1>Outline</h1>

<p>OK, I have Google'd this and already expecting a big fat <strong>NO!!</strong> But I thought I should ask since I know sometimes there can be the odd little gem of knowledge lurking around in peoples heads ^_^</p>

<p>I am working my way through some excercises in a book for study, and this particular exercise is User Controls. I have cobbled together a control and would like to set the DefaultEvent for it (having done this for previous controls) so when I double-click it, the default event created is whatever I specify it to be. </p>

<p><strong>NOTE:</strong> This is a standard User Control (.ascx), <em>NOT</em> a custom rendered control.</p>

<h2>Current Code</h2>

<p>Here is the class &amp; event definition:</p>

<pre><code>[System.ComponentModel.DefaultEvent("OKClicked")]
public partial class AddressBox : System.Web.UI.UserControl
{
    public event EventHandler OKClicked;
</code></pre>

<h2>Current Result</h2>

<p>Now, when I double click the the control when it is on a ASPX page, the following is created:</p>

<pre><code>    protected void AddressBox1_Load(object sender, EventArgs e)
    {

    }
</code></pre>

<p>Not quite what I was expecting! So, my question:</p>

<h2>Is it possible to define a DefaultEvent for a UserControl? Is it a hack? If it's [not] supported, is there a reason?</h2>

<hr>

<p><strong>Side Note</strong>: How do we put underscores in code? I cant seem to put and escape char in?</p>

[{'answer_id': 11271, 'author': 'Rob Cooper', 'author_id': 832, 'author_profile': 'https://Stackoverflow.com/users/832', 'pm_score': 4, 'selected': True, 'text': '<p>I think to be honest you a better just boning up on your standard design patterns and applying them to the individual problems that you face in developing your UI.</p>\n<p>While there are common UI &quot;themes&quot; (such as dealing with modifier keys) the actual implementation may vary widely.</p>\n<p>I have O\'Reilly\'s <a href="http://www.amazon.co.uk/gp/redirect.html?ie=UTF8&amp;location=http%3A%2F%2Fwww.amazon.co.uk%2FHead-First-Design-Patterns%2Fdp%2F0596007124%2Fref%3Dpd_bbs_sr_1%3Fie%3DUTF8%26s%3Dbooks%26qid%3D1218730650%26sr%3D1-1&amp;tag=robcthegeek-21&amp;linkCode=ur2&amp;camp=1634&amp;creative=6738" rel="nofollow noreferrer">Head First Design Patterns</a> and <a href="http://www.amazon.co.uk/gp/redirect.html?ie=UTF8&amp;location=http%3A%2F%2Fwww.amazon.co.uk%2FHead-First-Design-Patterns-Poster%2Fdp%2F0596102143%2Fref%3Dpd_bbs_sr_3%3Fie%3DUTF8%26s%3Dbooks%26qid%3D1218730650%26sr%3D1-3&amp;tag=robcthegeek-21&amp;linkCode=ur2&amp;camp=1634&amp;creative=6738" rel="nofollow noreferrer">The Poster</a>, which I have found invaluable!</p>\n<h3>Shameless Plug : These links are using my associates ID.</h3>\n'}, {'answer_id': 11274, 'author': 'Antonio Haley', 'author_id': 390, 'author_profile': 'https://Stackoverflow.com/users/390', 'pm_score': 2, 'selected': False, 'text': '<p>I don\'t think the that benefit of design patterns come from trying to find a design pattern to fit a problem. You can however use some heuristics to help clean up your design in this quite a bit, like keeping the UI as decoupled as possible from the rest of the objects in your system.</p>\n\n<p>There is a pattern that might help out in this case, the <a href="http://en.wikipedia.org/wiki/Observer_pattern" rel="nofollow noreferrer">Observer Pattern</a>.</p>\n'}, {'answer_id': 221216, 'author': 'Micha', 'author_id': 29893, 'author_profile': 'https://Stackoverflow.com/users/29893', 'pm_score': 2, 'selected': False, 'text': '<p>perhaps you\'re looking for something like the \'MouseTrap\' which I saw in some articles on codeproject (search for UI Platform)?</p>\n\n<p>I also found this series very useful <a href="http://codebetter.com/jeremymiller/2007/07/26/the-build-your-own-cab-series-table-of-contents/" rel="nofollow noreferrer">http://codebetter.com/jeremymiller/2007/07/26/the-build-your-own-cab-series-table-of-contents/</a> where you might have a look at embedded controllers etc.</p>\n\n<p>Micha.</p>\n'}, {'answer_id': 321973, 'author': 'Draemon', 'author_id': 26334, 'author_profile': 'https://Stackoverflow.com/users/26334', 'pm_score': 2, 'selected': False, 'text': '<p>I know you said not as global as MVC, but there are some variations on MVC - specifically HMVC and PAC - which I think can answer questions such as the ones you pose.</p>\n\n<p>Other than that, try to write new code "in the spirit" of existing patterns even if you don\'t apply them directly.</p>\n'}, {'answer_id': 2999391, 'author': 'DTS', 'author_id': 270699, 'author_profile': 'https://Stackoverflow.com/users/270699', 'pm_score': 3, 'selected': False, 'text': '<p>Object-Oriented Design and Patterns by Cay Horstmann has a chapter entitled "Patterns and GUI Programming". In that chapter, Horstmann touches on the following patterns:</p>\n\n<ul>\n<li>Observer Layout Managers and the</li>\n<li>Strategy Pattern Components,</li>\n<li>Containers, and the Composite Pattern</li>\n<li>Scroll Bars and the Decorator Pattern</li>\n</ul>\n'}, {'answer_id': 11825280, 'author': 'ISTB', 'author_id': 1452934, 'author_profile': 'https://Stackoverflow.com/users/1452934', 'pm_score': 2, 'selected': False, 'text': '<p>You are looking at a professional application programming. I searched for tips and tricks a long time, without success. Unfortunately you will not find anything useful, it is a complicated topic and only with many years of experience you will be able to understand how to write efficiently an application. For example, almost every program opens a file, extracts information, shows it in different forms, allow processing, saving, ... but nobody explains exactly what the good strategy is and so on. Further, if you are writing a big application, you need to look at some strategies to reduce your compilation time (otherwise you will wait hours at every compilation). Impls idioms in C++ help you for example. And then there is a lot more. For this reason software developers are well paid and there are so many jobs :-)</p>\n'}]
['https://Stackoverflow.com/questions/11267', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/832/']