0

there's no event fired when TextBox changed : jQuery tested and work fine:

      <SharePoint:ScriptLink Language="javascript" 
          Name="~sitecollection/SiteAssets/content/Scripts/jquery-2.1.1.min.js" 
              runat="server" />

          $(document).ready(function () {

               $("#fbn").change(function () {
                  alert("fired");
               });
          });


    <asp:TextBox runat="server" ID="fbn" OnTextChanged="FilterByName" 
                     AutoPostBack="true"></asp:TextBox>
0

4 Answers 4

0

I think there is a better way of doing this.

Remove the OnTextChanged from the TextBox.

Then replace $("#fbn") with $('#' + '<%= fbn.ClientID %>')

The ID it shows in server side is different when the HTML code is rendered. So it will not hit from the jquery code.

1
<asp:TextBox runat="server" ID="fbn" CssClass="fbn" OnTextChanged="FilterByName" 
                     AutoPostBack="true"></asp:TextBox>

$(document).ready(function () {
    $(".fbn").change(function () {
        alert("fired");
    });
 );

You can also just register the event on the control as Chromanin suggested.

Another option is to use server tags to print the ID into the javascript.

$(document).ready(function () {
    $("#<$= fbn.ClientID %>").change(function () {
        alert("fired");
    });
 );
0

You're using the wrong attribute. OnTextChanged is for serverside event handling. You need the clientside event.

Use onchange instead.

<asp:TextBox runat="server" ID="fbn" onchange="FilterByName()" 
                     AutoPostBack="false"></asp:TextBox>
1
  • thanks first. but i attached the event automatically in javascript
    – ezzaam
    Commented Aug 13, 2014 at 15:03
0

AutoPostBack will cause a server postback which won't allow the javascript function to fire.

Also the ID of the control does not stay that simple value. Here you have a few options, if you are not worried about hitting multiple text boxes, use classes.

<asp:TextBox runat="server" ID="fbn" CssClass="fbn" OnTextChanged="FilterByName" 
                     AutoPostBack="true"></asp:TextBox>

$(document).ready(function () {
    $(".fbn").change(function () {
        alert("fired");
    });
 );

You can also just register the event on the control as Chromanin suggested.

Another option is to use server tags to print the ID into the javascript.

$(document).ready(function () {
    $("#<$= fbn.ClientID %>").change(function () {
        alert("fired");
    });
 );

AutopostBack

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.