views:

49

answers:

2

Is it possible to create a custom button -- web user control? I want certain java scripts to trigger when buttons are clicked. If so, are there any articles out there that explain the basics?

I completely understand that I can load javascript via .js link or dynamically at page load, but I would like to just drop a control on the page without manually adding code to every page on every one of my projects.

A: 

There is the IScriptControl interface you can implement. In MSDN are samples for that. It will take care of aumatic script including from a resource whenever it is shown on a page.

Sebastian P.R. Gingter
A: 

Add a new Web User Control to your project by going to the menu item Project | Add New, then selecting Web User Control. Then just drop a button on it like this:

<asp:Button ID="Button1" runat="server" 
    onclientclick="alert(&quot;Javascript Here.&quot;)" Text="Button" />

You can then use that in your project. Replace the onclientclick with the javascript you would like to run.

Jason Webb