locked
Render control that need ScriptManager, programmatically. RRS feed

  • Question

  • User2070100822 posted

    Hi..

    I am trying to render control(ComboBox) programmatically, and i am getting error that tell me that i have to add ScriptManager to the page.

    But, i did that, and still its not working:

    override protected void OnInit( EventArgs e )
    		{
    			this.Load += new System.EventHandler( this.Page_Load );
    			Page.Init += delegate
    			             	{
    				if (ScriptManager.GetInstance(Page) != null) return;
    				var sMgr = new ScriptManager();
    				Page.Form.Controls.AddAt(0, sMgr);
    			};
    			base.OnInit( e );
    		}


    And the render control html is:

    protected override void Render( System.Web.UI.HtmlTextWriter writer )
    {
    writer.WriteLine(Html.RenderControl(ComboBoxObject));
    }

    protected override void Render( System.Web.UI.HtmlTextWriter writer )
    		{
    			writer.WriteLine(Html.RenderControl(ComboBoxObject));
    		}

    The RenderControl Function:

    static public string RenderControl(Control ctrl)
    		{
    			var sb = new StringBuilder();
    			var tw = new StringWriter(sb);
    			var hw = new HtmlTextWriter(tw);
    
    			ctrl.RenderControl(hw);
    			return sb.ToString();
    		}

    Any idea...

    Thanks...

    Thursday, February 18, 2010 2:40 AM

Answers

All replies

  • User-184166755 posted

    Exactly, you need to add a ScriptManager for partial render. 

    It's something like this:

      <asp:ScriptManager ID="ScriptManager1" runat="server">
        </asp:ScriptManager>


    ScriptManager manages ASP.NET AJAX script libraries and script files, partial-page rendering...

    Hope this helps you.

    Thursday, February 18, 2010 3:59 AM
  • User2070100822 posted

    Hi..

    As you can see in the code i mention above, i did include ScriptManager in the code.

    So, what do i need?

    Thursday, February 18, 2010 4:23 AM
  • User-1011786642 posted

     Check this http://forums.asp.net/p/1039254/1777798.aspx

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, February 19, 2010 6:28 AM