Solved

Inline code event handlers

Posted on 2007-04-02
3
362 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …

617 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