开发者

Problem with ScriptManager when trying to email rendered contents of ASP.NET page

开发者 https://www.devze.com 2022-12-24 05:42 出处:网络
I recently added a Telerik control to an ascx that is included in an aspx page. This page has a \"Send email\" button, which when clicked will email the user the rendered output of the page. The Teler

I recently added a Telerik control to an ascx that is included in an aspx page. This page has a "Send email" button, which when clicked will email the user the rendered output of the page. The Telerik control I added requires a ScriptManager, so I added that to the ascx. However, now the email button won't work. I get the following error:

The control with ID 'myIdHere' requires a ScriptManager on the page. The ScriptManager must appear before any controls that need it.

I know the script manager exists because the page works fine when I go that url, it is only failing when it tries to email the rendered output.

Here's a code snippet, any ideas as to whether there is a problem with scriptmanager when doing this sort of thing?

Page EmailPage = new EmailBasePage();
System.Web.UI.HtmlControls.HtmlForm EmailForm = new System.Web.UI.HtmlControls.HtmlForm();
EmailPage.Controls.Add(EmailForm);
EmailForm.Controls.Add(contentTable); //this is the container with all the controls I want to email

StringBuilder SB = new StringBuilder();
StringWriter html = new StringWriter(SB);
HtmlTextWriter mhtmlWriter = new HtmlTextWriter(html);

Ema开发者_开发知识库ilPage.DesignerInitialize();
EmailPage.RenderControl(mhtmlWriter);
mhtmlWriter.Close();

Update The control "myIdHere" referenced in the error message is the Telerik RadComboBox control that requires a ScriptManager. It is a child control of the contentTable control that is added to EmailForm. The control hierarchy is like this:

contentTable  
|__UserControl1  
    |__ScriptManager1  
    |__UserControl2  
        |__Control "myIdHere", a Telerik RadComboBox requiring a ScriptManager


If you are sure that the page output contains the ASP.NET AJAX scripts (rendered by the ScriptManager control) then you can remove the server exception by setting

myIdHere.RegisterWithScriptManager = false;

This will remove the combobox dependency on a script manager control on the server. Note that the control will still need the ASP.NET AJAX client scripts in the browser, which is why you need to make sure that there is a ScriptManager on the page in the first place.

0

精彩评论

暂无评论...
验证码 换一张
取 消