简体   繁体   中英

Disabled asp button

i have asp button like this:

<asp:Button ID="ImportToDB" runat="server" OnClick="ImportToDB_Click" />

And i need to call a javascript function when mouseover on this button. So i have in page_load():

ImportToDB.Attributes.Add("onmouseover","javascript:OnButtonMove(" + ImportToDB.ClientID + ")");

javascript function:

<script language="JavaScript" type="text/javascript">
 function OnButtonMove(id) {
         //something
 }
</script>

Everithing work fine only if button is enabled . but when i disable button, this javascript function will never fire.

what i am trying to do: I have button and when is something wrong i just disable it. And when user mouseover this(disable) button, I show him DIV with a message.

Can someone tell me why i cannot call this JS function while button is disabled?

If the event is never fired when the button is disabled, you could put the button in a <div> and add the event handler to this instead. Then check if the button is disabled inside your javascript function.

When this button is disabled it can't be accessed from client side javascript only by server side code (post back), a work around to achieve this by client-side way is to use a div control above this button as Graham Clark says like this

<div onmouseover="javascript:OnButtonMove(this.children[0].id)">
    <asp:Button ID="ImportToDB" runat="server" Text="test" Enabled="false" />
</div>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM