Saturday, March 31, 2012

Text Box Problem

Hello,
I have a master page where my form has the Runat="server".
The master page as a control place holder, named "cphContent".
Then in a page which inherits from the master page I added a custom
control which I created.
This custom control is added to "cphContent" at runtime.
The custom control creates and adds 2 textboxes using
CreateChildControls.
I am getting an error:
System.Web.HttpException: Control 'ctl00_cphContent_by27cf_tbName' of
type 'TextBox' must be placed inside a form tag with runat=server.
I have no idea why do I get this error.
The form with Runat="server" is in the master page.
Anyway, can someone tell me how can I figure what is going on?
Thanks,
MiguelHere is my code.
I am adding and creating all controls at runtime in my pages.
---
Base.master:
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="fBase" runat="server"></form>
</body>
</html>
Base.master.vb:
Protected Sub Page_Init(ByVal sender As Object, ByVal e As EventArgs)
Handles Me.Init
Dim pContainer As New Panel
AddHandler pContainer.Init, AddressOf pContainer_Init
Me.Controls.Add(pContainer)
Dim cphContent As New ContentPlaceHolder
AddHandler cphContent.Init, AddressOf cphContent_Init
pContent.Controls.Add(cphContent)
End Sub
MyPage.aspx:
<%@. Page Language="VB" CodeFile="Default.aspx.vb" Inherits="_Default"
%>
MyPage.aspx.vb:
Protected Sub Page_Init(ByVal sender As Object, ByVal e As EventArgs)
Handles Me.Init
Dim by27fContactForm As New By27.Web.UI.Form.Contact
AddHandler by27fContactForm.Init, AddressOf by27fContactForm_Init
pContacts.Controls.Add(by27fContactForm)
End Sub
Class Contact in Namespace By27.Web.UI:
Namespace Web.UI.Form
' Content
<DefaultProperty("Text"), ToolboxData("<{0}:ContactForm
runat=server></{0}:ContactForm>")> _
Public Class Contact
Inherits WebControl
Dim by27cf_tbName As New WebControls.TextBox
Private Sub by27cf_tbName_Init(ByVal sender As Object, ByVal e As
System.EventArgs)
With by27cf_tbName
.CssClass = Me.TextBoxCssClass
.ID = "by27cf_tbName"
.Width = Unit.Percentage(100)
End With
End Sub
<Bindable(True), Category("Appearance"), DefaultValue(""),
Localizable(True)> Property TextBoxCssClass() As String
Get
If CStr(ViewState("TextBoxCssClass")) Is Nothing Then
Return String.Empty
Else
Return CStr(ViewState("TextBoxCssClass"))
End If
End Get
Set(ByVal Value As String)
ViewState("TextBoxCssClass") = Value
End Set
End Property
Protected Overrides Sub CreateChildControls()
AddHandler by27cf_tbName.Init, AddressOf by27cf_tbName_Init
MyBase.Controls.Add(by27cf_tbName)
' Create child controls
MyBase.CreateChildControls()
Me.ChildControlsCreated = True
End Sub
End Class
---
Thanks,
Miguel
shapper wrote:
> Hello,
> I have a master page where my form has the Runat="server".
> The master page as a control place holder, named "cphContent".
> Then in a page which inherits from the master page I added a custom
> control which I created.
> This custom control is added to "cphContent" at runtime.
> The custom control creates and adds 2 textboxes using
> CreateChildControls.
> I am getting an error:
> System.Web.HttpException: Control 'ctl00_cphContent_by27cf_tbName' of
> type 'TextBox' must be placed inside a form tag with runat=server.
> I have no idea why do I get this error.
> The form with Runat="server" is in the master page.
> Anyway, can someone tell me how can I figure what is going on?
> Thanks,
> Miguel
This is a bug of Visual Studio. A problem is that in content page you don't
have form
"shapper" <mdmoura@.gmail.com> wrote in message
news:1163016480.466822.19390@.m7g2000cwm.googlegroups.com...
> Hello,
> I have a master page where my form has the Runat="server".
> The master page as a control place holder, named "cphContent".
> Then in a page which inherits from the master page I added a custom
> control which I created.
> This custom control is added to "cphContent" at runtime.
> The custom control creates and adds 2 textboxes using
> CreateChildControls.
> I am getting an error:
> System.Web.HttpException: Control 'ctl00_cphContent_by27cf_tbName' of
> type 'TextBox' must be placed inside a form tag with runat=server.
> I have no idea why do I get this error.
> The form with Runat="server" is in the master page.
> Anyway, can someone tell me how can I figure what is going on?
> Thanks,
> Miguel
>

0 comments:

Post a Comment