Click here to Skip to main content
16,004,806 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
When I watch "head" object in visual studio in debug, so it writes "InnerText = (InnerText) threw an exception of type system.Web.HttpException."

Why it happens?

Dim head As HtmlHead = New HtmlHead()
        Dim title As HtmlTitle = New HtmlTitle()
        head.Controls.Add(title)



Thanks
Posted
Updated 6-Nov-10 23:33pm
v2

You forgot to add into your aspx page the following:

XML
<head runat="server">
</head>


Your html header must be runat=server in order to execute your code
 
Share this answer
 
Comments
TheAteist 7-Nov-10 7:24am    
What "runat='server'"?
This code was taken from .vb that was generated from aspx page.
I get this error only when I add title to head

why?
Ed Guzman 7-Nov-10 8:42am    
Look at the aspx page and add the code I gave you into it, not into .vb
TheAteist 8-Nov-10 2:36am    
I create the page programmaticall. Here is the whole code
Private Function buildTitleControl() As HtmlTitle
Return New HtmlTitle()
End Function
Private Function buildLinkControl() As HtmlLink
Dim link As HtmlLink = New HtmlLink()
link.Href = "inc/newsletter.css"
link.Attributes.Add("rel", "stylesheet")
link.Attributes.Add("type", "text/css")

Return link
End Function
Private Function buildHeadControl() As HtmlHead
Dim head As HtmlHead = New HtmlHead("head")
Dim title As HtmlTitle = buildTitleControl()

head.Controls.Add(title)
Dim link As HtmlLink = buildLinkControl()
head.Controls.Add(link)

Return head
End Function
Private Function buildFormControl(ByVal page As Page) As Control
Dim ascx As Control = page.LoadControl("NewsLetter.ascx")
Return ascx
End Function

Private Function buildHtml() As String
Dim page As Page = New Page

page.Controls.Add(New LiteralControl("\r\n<!DOCTYPE html PUBLIC ""-//W3C//DTD XHTML 1.0 Transitional//EN"" ""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"">\r\n\r\n<html xmlns=""http://www.w3.org/1999/xhtml"">\r\n"))
Dim head As HtmlHead = buildHeadControl()
page.Controls.Add(head)
page.Controls.Add(New LiteralControl("\r\n<body>\r\n<div>\r\n"))
Dim form As Control = buildFormControl(page)
page.Controls.Add(form)
page.Controls.Add(New LiteralControl("\r\n</div>\r\n</body>\r\n</html>\r\n"))

page.ProcessRequest(HttpContext.Current)

Dim sb As StringBuilder = New StringBuilder()
Dim sw As StringWriter = New StringWriter(sb)
Dim htw As HtmlTextWriter = New HtmlTextWriter(sw)
page.RenderControl(htw)

Return sb.ToString()
}
Actually this happens on any other property as well.

It is because you are checking a property which does have definition but not everything correctly initialized.
 
Share this answer
 
Comments
TheAteist 7-Nov-10 5:35am    
I improved the code.
Before the execution of "head.Controls.Add(title)":
1 - When I watch "head" it shows - "{InnerText = ""}"
2 - When I wathc "title" it shows - "{System.Web.UI.HtmlControls.HtmlTitle}"
After the exectuion of head.Controls.Add(title)":
When I watch "head" it shows "{InnerText = (InnerText) threw an exception of type System.Web.HttpException.}"

Why? How to fix it?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900