tags:

views:

670

answers:

3

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?

A: 

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.

Jim Schubert
it actually does a postback to the asmx instead of the aspx page i loaded it to. the ascx generated is looking for a <form runat="server"> any clue on how to fix this?
its posting back to the asmx instead of the aspx it was loaded to. the error thrown is its looking for a <form runat="server"> tag.
edited my comment to add a couple more ideas for why it's not working.
Jim Schubert
A: 

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;
    }
}
@Martin i got the same error:"System.Web.HttpException: Control 'ctl00_Button1' of type 'Button' must be placed inside a form tag with runat=server." As this states that your from tag doesnot contain runat="server" attribute: <form id="form1" runat="server"> .........................</form>
Raghav Khunger
+1  A: 

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.