Dustin Getz
Dustin Getz

Reputation: 21811

JS callback on asp button

Um, I have this guy:

<div class="buttonRight"><asp:Button ID="btnOK" runat="server" Text="OK" Width="68px"/></div>

which renders out to

<div class="buttonRight"> <input type="submit" name="_$_$pc$pc$tabTO$_$uc0$popupSelectCompetition$btnOK" value="OK" id="____pc_pc_tabTO___uc0_popupSelectCompetition_btnOK" style="width:68px;" /></div>

I need to call some javascript on that button without altering its behavior otherwise. I tried putting an OnClick asp attribute but that seems to be for postbacks to call server code, not passing through a javascript hook to the rendered html.

I also don't understand how the input being type='submit' affects me.

Upvotes: 0

Views: 1287

Answers (1)

Canavar
Canavar

Reputation: 48108

Add your client-side code to the OnClientClick property :

<div class="buttonRight">
    <asp:Button ID="btnOK" runat="server" Text="OK" Width="68px" 
       OnClientClick="alert('client side scripts here');"/>
</div>

OnClick property used for server side events.

Or add onclick attribute to your control like that at code behind :

btnOK.Attributes.Add("onclick", "alert('client side scripts here');");

Upvotes: 2

Related Questions