开发者

asp.net custom web user control -- button

开发者 https://www.devze.com 2022-12-29 20:19 出处:网络
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?

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(&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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号