Get clientid in user control from external javascript file

前端 未结 4 381
余生分开走
余生分开走 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 09:00

    Ok, a different approach, that I try to use a JavaScript-class style, and then initialize it for each control.

    In the external javascript file, write your code as:

    function oNameCls(ControlId1) {
    
        this.ControlId1 = ControlId1;
    
        this.DoYourWork1 = function() {
            // use the control id.
            // this.ControlId1
        }    
        this.DoYourWork2 = function() {
            // use the control id.
            // this.ControlId1
        }    
    
    }
    

    And on the control do the call like that.

    
    

    Hope now help better.

提交回复
热议问题