May 23, 2012

Missing a HtmlHead control when Ajax is involved

I had a web application, which was using Ajax. And I was using the Calendar Extender Control from the Ajax toolkit.

I was using a master page that references style sheets. Once I run the application, I got this message,

This page is missing a HtmlHead control which is required for the CSS stylesheet link that is being added. Please add <head runat="server" />.

StackTrace:
       at AjaxControlToolkit.ScriptObjectBuilder.RegisterCssReferences(Control control) in d:\hg\act\Server\AjaxControlToolkit\ExtenderBase\ScriptObjectBuilder.cs:line 303
       at AjaxControlToolkit.ExtenderControlBase.OnLoad(EventArgs e) in d:\hg\act\Server\AjaxControlToolkit\ExtenderBase\ExtenderControlBase.cs:line 305
       at System.Web.UI.Control.LoadRecursive()
       at System.Web.UI.Control.LoadRecursive()
       at System.Web.UI.Control.LoadRecursive()
       at System.Web.UI.Control.LoadRecursive()
       at System.Web.UI.Control.LoadRecursive()
       at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
 

I was searching for a solution for sometime and finally, found this solution. It was really a simple solution. All you need to do is,

1. Add a script manager
2. Add a javascript function

and finally everything works fine.

Solution :

Add the following for your page:

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

 
// here make a function which calls automatically

 
<scriptlanguage="javascript">

 
function show()

{

document.write("<head runat='server'></head>");
}
</script>

 

4 comments:

  1. hello , that really great. i had the same problem. i can now fix it. but the problem is

    document.write("");

    is being displayed on the webpage. how to get rid of this. ?

    ReplyDelete
  2. Try to replace the script tag using following and see...
    script language="javascript" type="text/javascript"

    ReplyDelete
  3. Worked like a charm!! Thanks for posting.

    ReplyDelete
  4. Really really helpful...

    ReplyDelete