JAVASCRIPT IN ASP.NET

S

Savas Ates

How can i add javascript code to my server control object ?

I want to add a javascript code when a user OnClick it ..

Is there any sample code or reference web site or knowledge to solve it ?

<asp:Button id="Button1" style="Z-INDEX: 101; LEFT: 6px; POSITION: absolute;
TOP: 6px" runat="server"
Text="Button"></asp:Button>
 
N

Nathan Sokalski

Use the Attributes property. Here is a simple little function I wrote for
myself to create rollovers, but it's a good example of how to use the
Attributes property:


Public Shared Sub AddRollover(ByVal img As Web.UI.WebControls.Image,
ByVal rollover As String)
'Adds the rollover feature to an Image or ImageButton (or other
class that inherits from an Image)
img.Attributes.Add("onmouseover", "this.src='" & rollover & "';")
img.Attributes.Add("onmouseout", "this.src='" & img.ImageUrl & "';")
End Sub


The Add method of the Attributes property takes two parameters, the
attribute's name and value, both of which are of type String. I'm sure you
can take it from here, if you want more help, just ask or look at the help
files. Good Luck!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top