Asp.net Usercontrol not rendering the HTMLs

Topics: General, Troubleshooting
Aug 3, 2011 at 8:17 AM

Hi,

 

I was following this URL (http://docs.composite.net/C1/ASP-NET/ASPNETFAQ.aspx?q=How+do+I+set+parameters+on+ASP.NET+Controls%3f) to add the asp.net usercontrol with parameters.

It executes successfully but it dint rendered the HTML content of the usercontrol.

 

Please find the source code below and appreciate your help.

namespace Custom
{
    /// <summary>
    /// Summary description for AspNetControlFactory
    /// </summary>
    public class AspNetControlFactory
    {
        [FunctionParameterDescription("controlType", "Enter control type", "enter any of following [popular, topriser, topfaller]", null)]
        [FunctionParameterDescription("marketList", "Enter market list", "The comma separated values of market ids", null)]
        public static Control GetPriceControl(string controlType, string marketList)
        {
            AddPriceControl ctrl = new AddPriceControl();
            ctrl.ControlType = controlType;
            ctrl.MarketList = marketList;
            return ctrl;
        }
    }
}

Thanks

Kishore

Aug 3, 2011 at 8:18 AM

and how does your AddPriceControl look like?

Aug 3, 2011 at 8:23 AM
Edited Aug 3, 2011 at 8:32 AM

burningice wrote:

and how does your AddPriceControl look like?

I've pasted the HTML Source of the usercontrol and I cant attach the image of the usercontrol layout

<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="AddPriceControl.ascx.cs" Inherits="SpreadexCMS.AddPriceControl" %> <link href="/Frontend/Spreadex/UserControls/css/style.css" rel="stylesheet" type="text/css" /> <div class="jumpToBox"> <div class="innerBox"> <%=HTML %> </div> </div> <script type="text/javascript"> var marketList = "<%=MarketList %>"; function LoadPricingHTML() { $.ajax({ type: "POST", url: "/Frontend/Spreadex/UserControls/Service.asmx/GetPriceHTML", data: "{ MarketList: \"" + marketList + "\"}", contentType: "application/json; charset=utf-8", dataType: "json", success: function (msg) { debugger; var html = (msg.d == undefined) ? msg : msg.d; alert(html); $(".innerBox").html(html); } }); } LoadPricingHTML(); </script>

The contents are populated dynamically.

Aug 3, 2011 at 8:31 AM

not sure what happended with your post there, if you intended to include some source or not... but i can say that there is nothing wrong with your Method Based Function provider, so you would have to tell us what your AddPriceControl control is doing. To test you could make a simple example like this that would render a string.

namespace Custom
{
    /// <summary>
    /// Summary description for AspNetControlFactory
    /// </summary>
    public class AspNetControlFactory
    {
        [FunctionParameterDescription("controlType", "Enter control type", "enter any of following [popular, topriser, topfaller]", null)]
        [FunctionParameterDescription("marketList", "Enter market list", "The comma separated values of market ids", null)]
        public static Control GetPriceControl(string controlType, string marketList)
        {
            var ctrl = new LiteralControl(controlType +" "+ marketList);
            return ctrl;
        }
    }
}

Aug 3, 2011 at 8:35 AM

its printing the values as per your sample! but how do I get those in my usercontrol

Aug 3, 2011 at 8:48 AM

Well, if its a real usercontrol, then you cant instantiate it with its class-contructor, since that will ONLY grab the code behind, and not your content inside the ascx file. There is specific articles on that topic Create Instances of ASP.NET User Controls Programmatically. In your case it would be

namespace Custom
{
    /// <summary>
    /// Summary description for AspNetControlFactory
    /// </summary>
    public class AspNetControlFactory
    {
        [FunctionParameterDescription("controlType", "Enter control type", "enter any of following [popular, topriser, topfaller]", null)]
        [FunctionParameterDescription("marketList", "Enter market list", "The comma separated values of market ids", null)]
        public static Control GetPriceControl(string controlType, string marketList)
        {
            var page = HttpContext.Current.Handler as Page;
            if (page != null)
            {
               var ctrl = (AddPriceControl)page.LoadControl(".../path/to/control");
               ctrl.ControlType = controlType;
               ctrl.MarketList = marketList;
               return ctrl;
            }

            return null;            
        }
    }
}

Aug 3, 2011 at 9:16 AM
burningice wrote:

Well, if its a real usercontrol, then you cant instantiate it with its class-contructor, since that will ONLY grab the code behind, and not your content inside the ascx file. There is specific articles on that topic Create Instances of ASP.NET User Controls Programmatically. In your case it would be

 

namespace Custom
{
    /// <summary>
    /// Summary description for AspNetControlFactory
    /// </summary>
    public class AspNetControlFactory
    {
        [FunctionParameterDescription("controlType", "Enter control type", "enter any of following [popular, topriser, topfaller]", null)]
        [FunctionParameterDescription("marketList", "Enter market list", "The comma separated values of market ids", null)]
        public static Control GetPriceControl(string controlType, string marketList)
        {
            var page = HttpContext.Current.Handler as Page;
            if (page != null)
            {
               var ctrl = (AddPriceControl)page.LoadControl(".../path/to/control");
               ctrl.ControlType = controlType;
               ctrl.MarketList = marketList;
               return ctrl;
            }

            return null;            
        }
    }
}

 

Thanks burningice! the above suggestion solved my issue.