使用 jquery 在 web 服务中加载 ascx 时出现问题

发布于 2024-07-30 10:51:49 字数 315 浏览 3 评论 0原文

我使用这个示例并在 ascx 控件中创建了一个表单。

http://encosia.com/2008 /02/05/boost-aspnet-performance-with-deferred-content-loading/

问题是,每当我放置 asp.net 按钮或更新面板时,ascx 都不会加载。 可能是什么问题呢?

I used this example and created a form within the ascx control.

http://encosia.com/2008/02/05/boost-aspnet-performance-with-deferred-content-loading/

the problem is, whenever i place a asp.net button or an update panel, the ascx doesn't load. what could be the problem?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

末骤雨初歇 2024-08-06 10:51:49

我发现您需要将控件放入 HtmlForm 类中,然后将 HtmlForm 放入 Page 类中。

我转而使用 IFrame。 也许我会以另一种方式使用这种技术。

感谢您的努力。

I've discovered that you need to place the control in a HtmlForm class then the HtmlForm to a Page class.

I'm resorting back to using IFrames instead. Maybe I'll use this technique in another way.

thanks for the effort.

旧人 2024-08-06 10:51:49

您是否在 Web 服务的方法中放置了一个断点来查看它是否真正命中了 Web 服务?

我考虑的另一个选择是使用 XML 样式表,并使用样式表和 XML 服务器控件来转换此数据。 与添加更新面板并调用 Web 服务进行转换相比,这会消耗更少的开销。

另外,请检查以确保您的脚本管理器在您调用的页面上设置正确。

在你的 aspx 中,确保你的代码看起来类似于:

     <form id="form1" runat="server">
      <asp:ScriptManager runat="server">
        <Services>
          <asp:ServiceReference Path="~/RSSReader.asmx" />
        </Services>
        <Scripts>
          <asp:ScriptReference Path="~/Default.js" />
        </Scripts>
      </asp:ScriptManager>
     </form>
    <div id="Container">
      <div id="RSSBlock">
        <div id="RSSContent" class="loading"></div>
      </div>    
      <div id="Content">
      <p></p>
      </div>
    </div>

另外,他的教程没有提到这一点,但是你必须在你的 Web 服务的类上拥有这个属性,才能从 javascript 调用它:

[System.Web.Script.Services.ScriptService]

除了这些想法之外,我还想必须查看您的代码。

Did you put a breakpoint inside your web service's method to see if it's actually hitting the webservice?

Another option that I'd look at is using an XML Stylesheet and just transforming this data using a stylesheet and the XML Server control. That would use less overhead than adding an updatepanel and calling a web service for your transformation.

Also, check to make sure your scriptmanager is set up correctly on the page you're calling from.

In your aspx, make sure your code looks similar to:

     <form id="form1" runat="server">
      <asp:ScriptManager runat="server">
        <Services>
          <asp:ServiceReference Path="~/RSSReader.asmx" />
        </Services>
        <Scripts>
          <asp:ScriptReference Path="~/Default.js" />
        </Scripts>
      </asp:ScriptManager>
     </form>
    <div id="Container">
      <div id="RSSBlock">
        <div id="RSSContent" class="loading"></div>
      </div>    
      <div id="Content">
      <p></p>
      </div>
    </div>

Also, his tutorial doesn't mention this, but you have to have this attribute on your web service's class for it to be callable from javascript:

[System.Web.Script.Services.ScriptService]

Other than those ideas, I'd have to see your code.

深巷少女 2024-08-06 10:51:49

谢谢你的提示。 尽管如此,我还是遇到了同样的错误:

“System.Web.HttpException:‘Button’类型的控件‘ctl00_Button1’必须放置在带有 runat=server 的表单标记内。”

我正在动态 js JQuery 选项卡中加载控件。

$.ajax({
                type: "POST",
                url: "TabLoader.asmx/LoadNewTab",
                data: "{'fullname':'" + fullname +
                      "', 'id':'" + id + "'}",
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function(msg) {
                $(tabName).html(msg.d);
                }
            });

对于 asmx:

[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.Web.Script.Services.ScriptService]
[Serializable]
public class TabLoader : System.Web.Services.WebService
{
    private Page _page;

    [WebMethod]
    public string LoadNewTab(string fullname, string id)
    {
        _page = new Page();
        UserControl ctl = LoadControl("~/controls/ctrlTabContent.ascx", 
                                      fullname, 
                                      Convert.ToInt32(id));
        _page.Controls.Add(ctl);

        StringWriter writer = new StringWriter();
        HttpContext.Current.Server.Execute(_page, 
                                           writer, 
                                           false);

        return writer.ToString();
    }

    private UserControl LoadControl(string userControlPath, 
                                    params object[] constructorParams)
    {
        List<Type> constParamTypes = new List<Type>();
        foreach (object cp in constructorParams)
        {
            constParamTypes.Add(cp.GetType());
        }

        UserControl userCtrl = (UserControl)_page.LoadControl(userControlPath);
        ConstructorInfo constructor = userCtrl.GetType().BaseType.GetConstructor(constParamTypes.ToArray());
        if (constructor == null)
            throw new MemberAccessException("The requested constructor was not found on : " + userCtrl.GetType().BaseType.ToString());
        else
            constructor.Invoke(userCtrl, constructorParams);

        return userCtrl;
    }
}

thanks for the tip. still, i got the same error:

"System.Web.HttpException: Control 'ctl00_Button1' of type 'Button' must be placed inside a form tag with runat=server."

im loading the control inside a dynamic js JQuery tab.

$.ajax({
                type: "POST",
                url: "TabLoader.asmx/LoadNewTab",
                data: "{'fullname':'" + fullname +
                      "', 'id':'" + id + "'}",
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function(msg) {
                $(tabName).html(msg.d);
                }
            });

and for asmx:

[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.Web.Script.Services.ScriptService]
[Serializable]
public class TabLoader : System.Web.Services.WebService
{
    private Page _page;

    [WebMethod]
    public string LoadNewTab(string fullname, string id)
    {
        _page = new Page();
        UserControl ctl = LoadControl("~/controls/ctrlTabContent.ascx", 
                                      fullname, 
                                      Convert.ToInt32(id));
        _page.Controls.Add(ctl);

        StringWriter writer = new StringWriter();
        HttpContext.Current.Server.Execute(_page, 
                                           writer, 
                                           false);

        return writer.ToString();
    }

    private UserControl LoadControl(string userControlPath, 
                                    params object[] constructorParams)
    {
        List<Type> constParamTypes = new List<Type>();
        foreach (object cp in constructorParams)
        {
            constParamTypes.Add(cp.GetType());
        }

        UserControl userCtrl = (UserControl)_page.LoadControl(userControlPath);
        ConstructorInfo constructor = userCtrl.GetType().BaseType.GetConstructor(constParamTypes.ToArray());
        if (constructor == null)
            throw new MemberAccessException("The requested constructor was not found on : " + userCtrl.GetType().BaseType.ToString());
        else
            constructor.Invoke(userCtrl, constructorParams);

        return userCtrl;
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文