且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

从外部 javascript 文件中获取用户控件中的 clientid

更新时间:2023-02-12 21:50:20

好的,另一种方法,我尝试使用 JavaScript 类样式,然后为每个控件初始化它.

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

在外部 javascript 文件中,将代码编写为:

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.

<script language="Javascript" type="text/javascript">
    // init - create
    var <%=this.ClientID%>MyCls = new oNameCls(<%=Control1.ClientID%>);
    // do your work
    <%=this.ClientID%>MyCls.DoYourWork1();
</script>

希望现在能提供更好的帮助.

Hope now help better.