asp.net custom web user control -- button
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 witho开发者_Python百科ut manually adding code to every page on every one of my projects.
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.
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.
精彩评论