473,378 Members | 1,539 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Dynamically Created Control

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
Nov 18 '05 #1
5 1054
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" <jm**********************@formet.com> wrote in message
news:e3**************@TK2MSFTNGP12.phx.gbl...
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

Nov 18 '05 #2
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:OJ**************@TK2MSFTNGP12.phx.gbl...
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" <jm**********************@formet.com> wrote in message
news:e3**************@TK2MSFTNGP12.phx.gbl...
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


Nov 18 '05 #3
lol
Nov 18 '05 #4
Re-create it in the LoadViewstate event and then the View state will be
applied to it.

Ian
"Jason MacKenzie" <jm**********************@formet.com> wrote in message
news:e3**************@TK2MSFTNGP12.phx.gbl...
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

Nov 18 '05 #5
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" <jm**********************@formet.com> wrote in message
news:e3**************@TK2MSFTNGP12.phx.gbl...
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

Nov 18 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: DesignerX | last post by:
I have a user control that contains a custom control, both are loaded dynamically. The custom control has a simple required field validator and a text box to validate. When the submit button...
0
by: John Crowley | last post by:
I'm having an odd problem with viewstate and a dynamically created control inside a repeater template. Basically, I have a repeater setup like this in the aspx:
3
by: Jen | last post by:
Hi I have created some controls (HtmlInputText, HtmlGenericControl, TextBox) dynamically. But I have problem getting the values from these controls to save them. Is there a way to do that? ...
2
by: R Duke | last post by:
I have tried everything I can think of to change the visible property of a design time created control from a dynamically created control's command event handler. Here is the scenario. I have...
1
by: Mike | last post by:
I have a placeholder object in which I am dynamically placing controls based on a database query. Of course during postback these controls go away. I have seen other questions posed where someone...
1
by: Nirmalkumar | last post by:
How to attach an event to dynamically created control in VB.NET I have dynamically created dropdown list in code behind (VB.NET). For this control I want to attach an event for action...
7
by: mef526 | last post by:
I would like to reference a dynamically created control and I know the name. I would like to use the following: Dim strName as String = "txtControl1" ' This is the ".Name" used when textbox was...
3
by: RSH | last post by:
Hi, I have a situation where I have a page built in .Net 1.1 that I have a PlaceHolder in the Design. From the CodeBehind I am dynamically referencing a user control. This is a snippet from...
5
by: arnabit | last post by:
I have created a dropdown ,which is inside a panel and the panel is inside a place holder . the panel and the dropdown is created dynamically. I do have a button when the button is clicked i am...
1
by: Sami Rehman | last post by:
Hi, I am creating some web user controls dynamically Using LoadControl("ABC.ascx") My user control contains 2 drop down list, 2nd one is loaded based on the selection in the 1st one. However...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.