jreedinc
jreedinc

Reputation: 43

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 without manually adding code to every page on every one of my projects.

Upvotes: 1

Views: 428

Answers (2)

Jason Webb
Jason Webb

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

Upvotes: 0

Sebastian P.R. Gingter
Sebastian P.R. Gingter

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

Related Questions