Solved

Inline code event handlers

Posted on 2007-04-02
3
358 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

830 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