Reputation: 43
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.
Upvotes: 1
Views: 428
Reputation: 8020
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("Javascript Here.")" Text="Button" />
You can then use that in your project. Replace the onclientclick with the javascript you would like to run.
Upvotes: 0
Reputation: 6085
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.
Upvotes: 0