Adding attribute to button

liunx

Guest
I'm trying to add an attribute to my button so that when I click it, it calls the javascript function "clear();". This is what I have so far, but for some reason it is just not doing anything. I tried just putting a simple "alert" in the function but that isn't even doing anything

<code>
<script runat="server">
Sub Page_Load
clearButton.Attributes.Add("OnClick","clear();")
End Sub
</script>


<asp:button id="clearbutton" runat="server" text="Clear Alert"></asp:button>

</code>

Any ideas on how to make this work?Moved to .NETWhy can't you just put the onlick right in the button?try this:
clearButton.Attributes.Add("onclick","return clear();").
Use lower case for the "onclick", and add the "return" before "clear()".
I can't see any other reason why it won't work.
Use view source option to make sure the button got the event.
Regarding the previous reply: It just won't work. you can't add client event directly to a server control.
Good Luck
ALON
 
Back
Top