From: Rory Becker on 10 Jul 2008 13:14 The following code is the code behind of a blank page (With a scriptmanager) on which I'm trying to simulate a problem I'm having elsewhere in a larger app. The app is supposed, in this case, to dynamically create a textbox and a MaskEditExtender and associate the 2 together. I'm obviously doing something wrong as I'm getting a exception. ------------------------------------------------------------- [NullReferenceException: Object reference not set to an instance of an object.] AjaxControlToolkit.MaskedEditExtender.OnLoad(EventArgs e) +168 System.Web.UI.Control.LoadRecursive() +65 System.Web.UI.Control.LoadRecursive() +190 System.Web.UI.Control.LoadRecursive() +190 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2603 ------------------------------------------------------------- Any Ideas? -- Rory ------------------------------------------------------------- Public Partial Class ControlTesting Inherits System.Web.UI.Page Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load Controls.Add(New SpecialControl) End Sub End Class Public Class SpecialControl Inherits WebControl Implements INamingContainer Private Sub SpecialControl_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load Dim ControlAsTextBox As New TextBox ControlAsTextBox.ID = "TextBox" ControlAsTextBox.CssClass = "textbox" ControlAsTextBox.AutoCompleteType = AutoCompleteType.Disabled Dim Mask As String = "LL-#####" If Mask <> String.Empty Then Dim MyExtender As New AjaxControlToolkit.MaskedEditExtender MyExtender.Mask = Mask MyExtender.TargetControlID = ControlAsTextBox.ID MyExtender.MessageValidatorTip = True MyExtender.OnFocusCssClass = "MaskedEditFocus" MyExtender.OnInvalidCssClass = "MaskedEditError" MyExtender.MaskType = AjaxControlToolkit.MaskedEditType.None MyExtender.InputDirection = AjaxControlToolkit.MaskedEditInputDirection.LeftToRight MyExtender.AcceptNegative = AjaxControlToolkit.MaskedEditShowSymbol.None MyExtender.DisplayMoney = AjaxControlToolkit.MaskedEditShowSymbol.None MyExtender.ErrorTooltipEnabled = True Controls.Add(MyExtender) End If End Class -------------------------------------------------------------
From: Patrice on 10 Jul 2008 13:18 Hello, What if you add the TextBox to the "Controls" collection ? -- Patrice
From: Rory Becker on 10 Jul 2008 14:13 Hello Patrice" http:www.chez.com/scribe/, > What if you add the TextBox to the "Controls" collection ? > Doh! well I definitly needed to do that. However now I'm getting something else. I'm guessing it's because the textbox is not in the page hierarchy (only added thus far to the specialcontrol) when 2 controls are paired up. but I don't see how it could be as the specialcontrol has not yet been added to the page ------------------------------------------------------------- HttpException (0x80004005): Control 'ctl02_TextBox' of type 'TextBox' must be placed inside a form tag with runat=server.] System.Web.UI.Page.VerifyRenderingInServerForm(Control control) +2049759 System.Web.UI.WebControls.TextBox.AddAttributesToRender(HtmlTextWriter writer) +49 System.Web.UI.WebControls.WebControl.RenderBeginTag(HtmlTextWriter writer) +17 System.Web.UI.WebControls.TextBox.Render(HtmlTextWriter writer) +17 System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +25 System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +121 System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +22 System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +199 System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) +20 System.Web.UI.WebControls.WebControl.RenderContents(HtmlTextWriter writer) +7 System.Web.UI.WebControls.WebControl.Render(HtmlTextWriter writer) +29 System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +25 System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +121 System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +22 System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +199 System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) +20 System.Web.UI.Page.Render(HtmlTextWriter writer) +26 System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +25 System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +121 System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +22 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2558 -------------------------------------------------------------
From: George on 10 Jul 2008 14:42 Well, the error says it all...read it. " Control 'ctl02_TextBox' of type 'TextBox' must be placed inside a form tag with runat=server" I would highlight word "must" here.... George. "Rory Becker" <rorybecker(a)newsgroup.nospam> wrote in message news:3af103471910e8cab0d8294eaa78(a)news.microsoft.com... > Hello Patrice" http:www.chez.com/scribe/, > >> What if you add the TextBox to the "Controls" collection ? >> > > Doh! well I definitly needed to do that. > > However now I'm getting something else. > > I'm guessing it's because the textbox is not in the page hierarchy (only > added thus far to the specialcontrol) when 2 controls are paired up. but I > don't see how it could be as the specialcontrol has not yet been added to > the page > > > ------------------------------------------------------------- > HttpException (0x80004005): Control 'ctl02_TextBox' of type 'TextBox' must > be placed inside a form tag with runat=server.] > System.Web.UI.Page.VerifyRenderingInServerForm(Control control) +2049759 > System.Web.UI.WebControls.TextBox.AddAttributesToRender(HtmlTextWriter > writer) +49 > System.Web.UI.WebControls.WebControl.RenderBeginTag(HtmlTextWriter > writer) +17 > System.Web.UI.WebControls.TextBox.Render(HtmlTextWriter writer) +17 > System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, > ControlAdapter adapter) +25 > System.Web.UI.Control.RenderControl(HtmlTextWriter writer, > ControlAdapter adapter) +121 > System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +22 > System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, > ICollection children) +199 > System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) +20 > System.Web.UI.WebControls.WebControl.RenderContents(HtmlTextWriter > writer) +7 > System.Web.UI.WebControls.WebControl.Render(HtmlTextWriter writer) +29 > System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, > ControlAdapter adapter) +25 > System.Web.UI.Control.RenderControl(HtmlTextWriter writer, > ControlAdapter adapter) +121 > System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +22 > System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, > ICollection children) +199 > System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) +20 > System.Web.UI.Page.Render(HtmlTextWriter writer) +26 > System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, > ControlAdapter adapter) +25 > System.Web.UI.Control.RenderControl(HtmlTextWriter writer, > ControlAdapter adapter) +121 > System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +22 > System.Web.UI.Page.ProcessRequestMain(Boolean > includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2558 > > ------------------------------------------------------------- > >
From: Rory Becker on 10 Jul 2008 15:17 Hello george, > Well, the error says it all...read it. > " Control 'ctl02_TextBox' of type 'TextBox' must be placed inside a > form tag > with runat=server" > I would highlight word "must" here.... > > George. > I was about to reply that "as far as I knew" the textbox was in the form. After all .. what else have I been adding it to? Then I thought about that question for a moment. For anyone else who might have come across this.... ------------------------------------------------------------- Controls.Add(SomeControl) ------------------------------------------------------------- ....is not the same as... ------------------------------------------------------------- Form1.Controls.Add(SomeControl) ------------------------------------------------------------- Thanks for the tip George :) Now all I have to do is to sort out that AJaxPro conflict.. ( thats for another post) Thanks again -- Rory
|
Pages: 1 Prev: Error: Subreport could not be shown Next: Microsoft Office Excel cannot access the file (IIS7) |