Solved

Inline code event handlers

Posted on 2007-04-02
3
353 Views
Last Modified: 2013-11-26
Hello Experts

I am using Visual Studio.NET 2005 for ASP.NET (C#) development. Whenever I double click a control that I drag onto my webform (from the toolbox) it generates the default event handler in the code behind. Is there any way to get the event handler to appear inline with the HTML source (in a <script> tag) rather than the code behind by default?

Thank you
0
Comment
Question by:Programmer_to_be
  • 2
3 Comments
 
LVL 25

Accepted Solution

by:
dstanley9 earned 50 total points
Comment Utility
Are you talking about a server-side <script> block (<script runat="server">, or a client-side JavaScript block?  If you double-click a control, VS will always generate a server-side script and always put it in the code-behind.  It's a fundamental peice of the MVC pattern (separating the code from the form) used by ASP.NET.  You could copy the code-behind to a server-side script block, but it will not work in a client side script.  You'll have to code that manually.
0
 

Author Comment

by:Programmer_to_be
Comment Utility
Hi dstanley9, yes I'm refering to a server side script block not client side. I am in the process of learning web development and came across the concept of "inline code" organisation and "code behind" organisation. I briefly know the pros and cons associated with each approach (i.e. code behind seperates concerns etc), and just wanted to know if it was possible to automatically generate an event handler method in a script block rather than the code behind (in VS.NET 2005).

Are you therefore saying that I'll have to copy the event handler across from the code behind to the html source in a script block?

Thanks for your help
0
 
LVL 25

Expert Comment

by:dstanley9
Comment Utility
Yes that is correct.  One other "disadvantage" is that the method does not show up in the drop-down listts in the properties window as a valid event handler.  However, VS is smart enough to take you to the inline code when you double-click the control _after_ you have copied and pasted the code.
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now