【问题标题】:Alternate way to use page method inside user control asp.net在用户控件asp.net中使用页面方法的替代方法
【发布时间】:2011-03-08 07:31:19
【问题描述】:

有没有一种方法可以在用户控件中实现页面方法的功能。

感谢任何帮助,谢谢:)

【问题讨论】:

    标签: asp.net ajax user-controls pagemethods


    【解决方案1】:

    最简单的方法可能是将您想要的功能放入网络服务中,然后使用scriptservice 属性使其可用。

    与页面方法非常相似。

    相当广泛的例子here

            <asp:ScriptManager>
                <Services>
                    <asp:ServiceReference Path="~/MyWs.asmx" />
                </Services>
            </asp:ScriptManager>
    

    然后你可以在JS中调用你的webmethods:MyNamespace.MyWs.MyMethod();

    【讨论】:

      【解决方案2】:

      对我有用的是将我的 WebMethods 放在派生自 System.Web.UI.Page 的自定义类中

      public class MyPage : System.Web.UI.Page
      {
          [WebMethod]
          public static bool MyMethod(string value)
          {
              return true;
          }
      }
      

      然后,每当我有一个包含需要使用该 WebMethod 的用户控件的页面时,我都会从我的自定义页面类而不是 System.Web.UI.Page 派生该页面。

      【讨论】:

        猜你喜欢
        • 2019-09-04
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-10-27
        • 2014-03-09
        相关资源
        最近更新 更多