Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Dynamically Created Control

Reply
Thread Tools

Dynamically Created Control

 
 
Jason MacKenzie
Guest
Posts: n/a
 
      11-25-2004
I'm trying to capture the text property of a dynamically created textbox on
the screen.. I can't get this simple example to work. I get "Object
Reference Not set to instance....." on the Response.Write(text.Text) in the
Button1.Click event handler.

I'm sure this is something painfully simple.

Thanks a lot,

Jason MacKenzie

Public Class WebForm1
Inherits InformetBaseClass.PageFramework

Dim text As TextBox



Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Init


'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()

Dim text = New TextBox
CType(Me.FindControl("Form1"), HtmlForm).Controls.Add(text)
End Sub



Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Response.Write(text.Text)
End Sub

End Class


 
Reply With Quote
 
 
 
 
Karl Seguin
Guest
Posts: n/a
 
      11-25-2004
Public class WebForm1
inerhits Page

dim text as TextBox

sub init
dim text as new TextBox
Controls.Add(text)
end init

sub click
response.write(text.text)
end sub
end class

the text variable at the top is never assigned. Because in init you create
another text variable which is scoped to the function. Simply remove the dim
text as new TExtbox and replace it with text = new TextBox in init and
voila.

KArl

--
MY ASP.Net tutorials
http://www.openmymind.net/


"Jason MacKenzie" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> I'm trying to capture the text property of a dynamically created textbox

on
> the screen.. I can't get this simple example to work. I get "Object
> Reference Not set to instance....." on the Response.Write(text.Text) in

the
> Button1.Click event handler.
>
> I'm sure this is something painfully simple.
>
> Thanks a lot,
>
> Jason MacKenzie
>
> Public Class WebForm1
> Inherits InformetBaseClass.PageFramework
>
> Dim text As TextBox
>
>
>
> Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
> System.EventArgs) Handles MyBase.Init
>
>
> 'CODEGEN: This method call is required by the Web Form Designer
> 'Do not modify it using the code editor.
> InitializeComponent()
>
> Dim text = New TextBox
> CType(Me.FindControl("Form1"), HtmlForm).Controls.Add(text)
> End Sub
>
>
>
> Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
> System.EventArgs) Handles Button1.Click
> Response.Write(text.Text)
> End Sub
>
> End Class
>
>



 
Reply With Quote
 
 
 
 
Jason MacKenzie
Guest
Posts: n/a
 
      11-25-2004
You know Karl, I knew it was something dumb but I could not have pictured it
being THAT dumb.

Thank you sir.

"Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net>
wrote in message news:(E-Mail Removed)...
> Public class WebForm1
> inerhits Page
>
> dim text as TextBox
>
> sub init
> dim text as new TextBox
> Controls.Add(text)
> end init
>
> sub click
> response.write(text.text)
> end sub
> end class
>
> the text variable at the top is never assigned. Because in init you
> create
> another text variable which is scoped to the function. Simply remove the
> dim
> text as new TExtbox and replace it with text = new TextBox in init and
> voila.
>
> KArl
>
> --
> MY ASP.Net tutorials
> http://www.openmymind.net/
>
>
> "Jason MacKenzie" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>> I'm trying to capture the text property of a dynamically created textbox

> on
>> the screen.. I can't get this simple example to work. I get "Object
>> Reference Not set to instance....." on the Response.Write(text.Text) in

> the
>> Button1.Click event handler.
>>
>> I'm sure this is something painfully simple.
>>
>> Thanks a lot,
>>
>> Jason MacKenzie
>>
>> Public Class WebForm1
>> Inherits InformetBaseClass.PageFramework
>>
>> Dim text As TextBox
>>
>>
>>
>> Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
>> System.EventArgs) Handles MyBase.Init
>>
>>
>> 'CODEGEN: This method call is required by the Web Form Designer
>> 'Do not modify it using the code editor.
>> InitializeComponent()
>>
>> Dim text = New TextBox
>> CType(Me.FindControl("Form1"), HtmlForm).Controls.Add(text)
>> End Sub
>>
>>
>>
>> Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
>> System.EventArgs) Handles Button1.Click
>> Response.Write(text.Text)
>> End Sub
>>
>> End Class
>>
>>

>
>



 
Reply With Quote
 
Franck Quintana
Guest
Posts: n/a
 
      11-25-2004
lol
 
Reply With Quote
 
Ian Frawley
Guest
Posts: n/a
 
      11-25-2004
Re-create it in the LoadViewstate event and then the View state will be
applied to it.

Ian
"Jason MacKenzie" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> I'm trying to capture the text property of a dynamically created textbox

on
> the screen.. I can't get this simple example to work. I get "Object
> Reference Not set to instance....." on the Response.Write(text.Text) in

the
> Button1.Click event handler.
>
> I'm sure this is something painfully simple.
>
> Thanks a lot,
>
> Jason MacKenzie
>
> Public Class WebForm1
> Inherits InformetBaseClass.PageFramework
>
> Dim text As TextBox
>
>
>
> Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
> System.EventArgs) Handles MyBase.Init
>
>
> 'CODEGEN: This method call is required by the Web Form Designer
> 'Do not modify it using the code editor.
> InitializeComponent()
>
> Dim text = New TextBox
> CType(Me.FindControl("Form1"), HtmlForm).Controls.Add(text)
> End Sub
>
>
>
> Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
> System.EventArgs) Handles Button1.Click
> Response.Write(text.Text)
> End Sub
>
> End Class
>
>



 
Reply With Quote
 
Jeffrey Palermo [MCP]
Guest
Posts: n/a
 
      11-25-2004
Jason,
Just get rid of the Dim in your Init code. Like the following:
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Init

InitializeComponent()

text = New TextBox

CType(Me.FindControl("Form1"), HtmlForm).Controls.Add(text)

End Sub



Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click

Response.Write(text.Text)

End Sub


Best regards,
Jeffrey Palermo

"Jason MacKenzie" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> I'm trying to capture the text property of a dynamically created textbox

on
> the screen.. I can't get this simple example to work. I get "Object
> Reference Not set to instance....." on the Response.Write(text.Text) in

the
> Button1.Click event handler.
>
> I'm sure this is something painfully simple.
>
> Thanks a lot,
>
> Jason MacKenzie
>
> Public Class WebForm1
> Inherits InformetBaseClass.PageFramework
>
> Dim text As TextBox
>
>
>
> Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
> System.EventArgs) Handles MyBase.Init
>
>
> 'CODEGEN: This method call is required by the Web Form Designer
> 'Do not modify it using the code editor.
> InitializeComponent()
>
> Dim text = New TextBox
> CType(Me.FindControl("Form1"), HtmlForm).Controls.Add(text)
> End Sub
>
>
>
> Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
> System.EventArgs) Handles Button1.Click
> Response.Write(text.Text)
> End Sub
>
> End Class
>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Affecting a dynamically created drop down from another dynamically created drop down. msimmons ASP .Net 0 07-16-2009 03:17 PM
Managing ViewState of a dynamically created Custom Composite Server Control -(where the original is also dynamically created) dickster ASP .Net Building Controls 0 12-08-2005 09:32 AM
need help with dynamically created user control Karl Seguin ASP .Net 1 08-10-2003 08:46 PM
dynamically created control is not being validated DesignerX ASP .Net 2 07-24-2003 04:47 PM
returning values from dynamically created user control Duncan Welch ASP .Net 2 07-02-2003 03:23 PM



Advertisments