Geoorg
Geoorg

Reputation: 3

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?

Upvotes: 0

Views: 546

Answers (2)

Spyros
Spyros

Reputation: 540

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>

Upvotes: 0

Graham Clark
Graham Clark

Reputation: 12966

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.

Upvotes: 1

Related Questions