从aspx页面调用与用户控件绑定的Javascript方法

时间:2013-01-09 19:29:22

标签: c# javascript jquery asp.net custom-controls

所以我有一个自定义的asp.net控件,它有javascript。我希望能够从自定义控件所在页面上的自定义控件上的控件上调用ResetTimeout方法。

以下是我的代码的示例

    **TestControl.CS**

 [CLSCompliant(true)]
    [ToolboxData("<{0}:TestControl runat=server></{0}:TestControl >")]
    public class TestControl : WebControl, INamingContainer, IScriptControl, ICallbackEventHandler
    {

    }

  **TestControl.JS**

 // Timout Handler -- builds or resets the timeouts
 ResetTimeout: function () {
    this.HideControl();
    this.StartTimers();
},

 **TestPage.ASPX**


<asp:Content runat="server" ID="BodyContent" ContentPlaceHolderID="MainContent">
      <script type="text/javascript">
        function test() {
            ($("#<%=Test.ClientID%>").ResetTimeout());
        }
    </script>

 <cc1:TestControl id="Test" runat="server"> </TestControl>

</asp:Content>

1 个答案:

答案 0 :(得分:1)

将此更改为($("#<%=Test.ClientID%>").ResetTimeout());$find("<%= Test.ClientID %>").ResetTimeout();