Why can't I add the clientId of my textBox to the markup here so that I can find it using jQuery?

I'm just trying to pass the client identifier of one text element txtPersonId for a click event, so that I can go to this textBox control and pass its jQuery wrapper to the loadePerson () function.

This is how I decal it in the aspx label:

<asp:Button ID="btnSearch" runat="server" Text="ARA" OnClientClick="loadPerson(jQuery('#<%=txtPersonId.ClientID %>'))"/>

But when I draw it,

<%=txtPersonId.ClientID %>

the place keeper remains as it is, and it is not replaced by the display identifier of the management client.

Any idea why this is happening and how can I overcome it?

+3
source share
2 answers

, . , , , string.

 <asp:Button ID="btnSearch" runat="server" Text="ARA"
      OnClientClick='<%= "loadPerson(jQuery(\"#" + txtPersonId.ClientID + "\"))" %>' />

, javascript , . javascript , , DOM script. "end with" id, - .

 <script type="text/javascript">
      $(function() {
          $('#' + '<%= btnSearch.ClientID %>').click( function() {
                loadPerson( $('input[id$=txtPersonId]') );
          });
      });
 </script>
+4

, LoadPerson, click Jquery, - :

'#' + '<% = txtPersonId.ClientID% > ', txtbox, - $('#' + '<% = btnSearch.ClientID% > '). click (function() {// });

0

Source: https://habr.com/ru/post/1750853/


All Articles