1

I have a textbox,

<input type="text" id="hoverChange" runat="server" onchange="hoverAction"/>

I have the below method defined in the server side code,

protected void hoverAction(object sender, EventArgs e)
{
    string sectionName=hoverChange.Value;
    if (sectionName != "") sectionHoverUserControl.displayHoverContent(sectionName);
}

I need the above method to be executed when I programatically set some value to the textbox. I tried to do the below, But neither fired the onchange event,

document.getElementById('<%= hoverChange.ClientID %>').value = "some_text";

or

$('#<%= hoverChange.ClientID %>').val("some_text");

I would appreciate your help! Thanks, Harish

2 Answers 2

1

The browser does not fire "change" events when you update the value of an input programmatically. You can, with jQuery, do this:

$('#<%= hoverChange.ClientID %>').val("some_text").change();

to trigger the event yourself. (You can do it without jQuery, but it's a bit more involved.)

Sign up to request clarification or add additional context in comments.

1 Comment

I realize the post isn't tagged jQuery, but it was used in the body of the question so I call fair :-)
0

use keyup event to fire the necessary code..

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.