Get clientid in user control from external javascript file

前端 未结 4 383
余生分开走
余生分开走 2020-12-06 08:32

I am developing a user control (ascx) in ASP.NET which uses javascript for manipulating controls. Currently the javascript code is inlined and uses <%= somecontrol.

4条回答
  •  一生所求
    2020-12-06 08:36

    If you want to find a specific control when there could be multiple copies, this can't be done. How would the external javascript know which of the n controls you wanted?

    How can rig the behavior up to a class and find the elements relative to the position of the action control, like this:

    UserControl:

    Show me!

    If you jQuery was written to be relative like this:

    $(".myControl input").click(function() {
      $(this).next().slideDown();
    });
    

    In this case, it doesn't matter what the specific IDs are, as long as you can navigate the DOM relatively to the controls you need. Even if it's more complex like .closest("div").next().find(".bob").prev()...whatever you need to get there works.

提交回复
热议问题