0

I use keyup but it does not fire. I populate innerHtml of div via GetRecords() from webmethod with a table and input text as a search. I click a button GetRecords fires, then webmethod is called. Then I create a table format on c# as table and input text.

function GetRecords() {
PageMethods.GetSavedList(onSucess, onError);
function onSucess(result) {
    document.getElementById('allRecordsDiv').innerHTML = result;
}
function onError(result) {
    alert("error..");
}
}

script side;

$("#mySearchInput").keyup(function () {
alert("aasdasd")
});

c# side;

    [WebMethod]
    [ScriptMethod]
    public static string GetSavedList()
    {
        DataTable dt = DBoperation.GetAllRecords();
        string html = "<table id= \"savedlist\" class=\"table table-hover\">";
        //add header row
        html += "<thead>";
        html += "<tr>  <input class=\"form-control\" id=\"mySearchInput\" type=\"text\" placeholder=\"Search..\"></ tr>";
        html += "<tr>";
        html += "<th> </th>";
        for (int i = 0; i < dt.Columns.Count; i++)
        {
                html += "<th>" + dt.Columns[i].ColumnName + "</th>";
        }
        html += "<th>  </th>";
        html += "</thead>";

        html += "<tbody id=\"mySavedListTable\">";

        //add rows
        for (int i = 0; i < dt.Rows.Count; i++)
        {
            //some rows
        }
        html += "</tbody>";

        html += "</table>";
        return html;
    }
Camilo Terevinto
  • 26,697
  • 6
  • 67
  • 99
  • You probably bind the event while the element you are binding to is not yet present on the page. You should wait for your page to load before binding events using `window.onload`. – BoltKey May 29 '18 at 23:05
  • Note: You can't repeat element ID's in a page. They are unique by definition. Use common classes on repeating elements – charlietfl May 29 '18 at 23:11
  • The code you've shown never called the webmethod, just calls an alert. – Ryan Gibbs May 29 '18 at 23:12

0 Answers0