Solved

Inline code event handlers

Posted on 2007-04-02
3
355 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
ID: 18836194
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
ID: 18836278
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
ID: 18836475
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…

861 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

30 Experts available now in Live!

Get 1:1 Help Now