While attempting to print the contents of an HTML DIV using the provided code, everything worked smoothly. However, upon integrating an Ajax Control into an Aspx page, an error message surfaced:
"Extender control 'CalendarExtender2' is not a registered extender control. Extender controls must be registered using RegisterExtenderControl() before calling RegisterScriptDescriptors(). Parameter name: extenderControl"
The C# code used is as follows:
protected void BtnPrint_Click(object sender, EventArgs e)
{
StringWriter stringWrite = new StringWriter();
System.Web.UI.HtmlTextWriter htmlWrite = new System.Web.UI.HtmlTextWriter(stringWrite);
Page pg = new Page();
pg.EnableEventValidation = false;
HtmlForm frm = new HtmlForm();
pg.EnableEventValidation = false;
pg.Controls.Add(frm);
frm.Attributes.Add("runat", "server");
frm.Controls.Add(divContent);
pg.DesignerInitialize();
pg.RenderControl(htmlWrite);
string strHTML = stringWrite.ToString();
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.Write(strHTML);
HttpContext.Current.Response.Write("<script>window.print();</script>");
HttpContext.Current.Response.End();
}
The Aspx code utilized is as shown below:
<%@ Page Title="" Language="C#" MasterPageFile="~/Masters/TSAMaster.master" AutoEventWireup="true"
EnableEventValidation="false" Theme="skinFiles" CodeFile="AdminHome.aspx.cs"
Inherits="Masters_Default" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajaxToolkit" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
... [code continues with various script and markup]
It was discovered that replacing frm.Controls.Add(tblOne)
with frm.Controls.Add(divContent)
resulted in successful execution, as tblone
does not contain an Ajax Control. However, when incorporating both tables and Ajax Controls within divContent
, the aforementioned exception arises. Various solutions were explored such as overriding OnInit
and OnPreRender
, unfortunately without success.