Get user input from dynamic created control, why i cant get the value???

Hi!, i was tried to dynamically generate some textboxes according the selected number in a dropdownlist, but when i need to get the user input from those textboxes.. i cant get at all!!, Can any1 guide me on tis? Below is my code.
Basically, i have 1 dropdownlist (ddltbCount), 1 placeHolder(Pholder1), 1 button(btGetValue), i dont know y i cant post the html here...

Private count As Integer = 1

Sub IterateThroughChildren(ByVal parent As Control)
For Each c As Control In parent.Controls
If c.GetType.ToString.Equals("System.Web.UI.WebControls.TextBox") AndAlso c.ID Is Nothing Then
' CType(c, TextBox).Text = "TextBox " + count.ToString
CType(c, TextBox).Columns = 10
System.Math.Min(System.Threading.Interlocked.Increment(count),count-1)
End If
If c.Controls.Count > 0 Then
IterateThroughChildren(c)
End If
Next
End Sub

Sub btGetValue_Click(ByVal Sender As Object, e As EventArgs)
For Each c As Control In Pholder1.Controls
Response.write(Ctype(c,TextBox).Text)
Next
DdltbCount_SelectedIndexChanged(Sender,E)
End Sub

Sub DdltbCount_SelectedIndexChanged(sender As Object, e As EventArgs)
Dim n As Integer = Int32.Parse(DdltbCount.SelectedItem.Text)
Dim i As Integer = 0
While i < n
Pholder1.Controls.Add(New TextBox)
System.Math.Min(System.Threading.Interlocked.Increment(i),i-1)
End While
IterateThroughChildren(Me)
End Sub

Any documentation is also welcome, i really stuck n dumb....

Regards
life's Ng

0
life
4/25/2005 11:11:18 AM
asp.net.web-forms 93655 articles. 5 followers. Follow

8 Replies
1135 Views

Similar Articles

[PageSpeed] 31

 

Hi,

I have written an article on getting the selected item of all RadioButtonList in a page which are generated dynamically.

You can use the same code with slight modification for TextBox as and when required and get the value of all the textboxes.

Please check http://harishmvp.blogspot.com/2004/08/how-to-get-selectedvalue-of-all-list.html

Write back if this doesn't help.

 


regards,
Harish

http://geekswithblogs.net/ranganh
0
ranganh
4/25/2005 2:43:56 PM

Hi, Thanks, But i still cant make it work..... i get nothing from the tb, is tat my logic got wrong? What should i do???

Private Sub btGetValue_Click(ByVal sender As Object, ByVal e As System.EventArgs)
For Each ctl As System.Web.UI.Control In Pholder1.Controls 
   LoopAllControls(ctl)
Next
DdltbCount_SelectedIndexChanged(sender, E)
End Sub

Public Sub LoopAllControls(ByVal oControl As System.Web.UI.Control) 
   For Each frmControl As System.Web.UI.Control In Pholder1.Controls 
      If frmControl.GetType.ToString ="System.Web.UI.WebControls.TextBox" then 
         dim tb as textbox=New textbox 
         tb=ctype(frmcontrol, textbox) 
         Response.Write(tb.Text) 
      End If 
      If frmControl.HasControls Then 
         LoopAllControls(frmControl) 
      End If 
   Next
End Sub

Regards
life's Ng

0
life
4/26/2005 2:08:28 AM
any one can show me what i did wrong here..?
0
life
4/27/2005 1:22:48 AM
0
vick93
4/27/2005 3:13:05 AM

Thanks Vick,

im using webmatrix, and i dont know wat is the code below, so i just disable it:

    ' CODEGEN: The Web Form Designer requires this method call.
    ' Do not modify it by using the code editor.
    ' InitializeComponent()


But i receive an error :

Multiple controls with the same ID 'TextBox1' were found. FindControl requires that controls have unique IDs.

if i use InitializeComponent(), i receive the error below...

Name 'InitializeComponent' is not declared.

How can i know what is the event do?

0
life
4/27/2005 7:19:48 AM

don't disable any code generated by ID and make sure every conrol you generate has a unique ID.

Best of luck,

Vick


http://vikasnetdev.blogspot.com
0
vick93
4/27/2005 11:18:09 AM

Hi Vick, Thanks for ur reply, but if i dont get rid of the  InitializeComponent(), i wont be able to proceed. it show me error:

Compiler Error Message: BC30451: Name 'InitializeComponent' is not declared.

 

0
life
4/28/2005 2:13:28 AM

Here is working code. I am using Visual Studio.Net. I just have web form with panel control and button control to test. I am loading text boxes dynamically.

hope this helps, good night Smile [:)]

Vick

 

<code>

Public Class WebForm1

Inherits System.Web.UI.Page

#Region " Web Form Designer Generated Code "

'This call is required by the Web Form Designer.

<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

End Sub

'NOTE: The following placeholder declaration is required by the Web Form Designer.

'Do not delete or move it.

Private designerPlaceholderDeclaration As System.Object

Private TextBox1 As TextBox

Protected WithEvents Panel1 As System.Web.UI.WebControls.Panel

Protected WithEvents GetValues As System.Web.UI.WebControls.Button

Private TextBox2 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()

End Sub

#End Region

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

'Put user code to initialize the page here

'If Not Page.IsPostBack Then

TextBox1 = New TextBox

TextBox1.ID = "TextBox1"

TextBox1.Style("Position") = "Absolute"

TextBox1.Style("Top") = "25px"

TextBox1.Style("Left") = "100px"

Me.Panel1.Controls.Add(TextBox1)

TextBox2 = New TextBox

TextBox2.ID = "TextBox2"

TextBox2.Style("Position") = "Absolute"

TextBox2.Style("Top") = "60px"

TextBox2.Style("Left") = "100px"

Me.Panel1.Controls.Add(TextBox2)

'End If

End Sub

Private Sub GetValues_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles GetValues.Click

Dim Control1 As Control

Dim Value As String

For Each Control1 In Me.Panel1.Controls

If TypeOf (Control1) Is TextBox Then

Value = CType(Control1, TextBox).Text

End If

Next

 

End Sub

End Class

 

 

<code>

 


http://vikasnetdev.blogspot.com
0
vick93
4/28/2005 4:20:52 AM
Reply:

Similar Artilces:

How get value from a dynamically created control in a user control
HI, I am working with a version of IBuySpy. On one page is a form that contains a user control that lists the items the user purchased, the subtotal, shipping, etc. I wanted to add a DropDownList from which the user could select the shipper. The dropdown list works fine as long as it has .AutoPostBack = false. However, I cannot figure out how to get the value that the user selected when they finally press the submit button on the form. All attempts to locate the control and it's value have failed. I tried drillingdown from the form to the child controls, and sub child controls. N...

Getting User Input from Dynamic created controls
Hi, i have a problem getting the user input (values) from dynamically created controls.I create the dynamic controls in the onInit event and assign each a unique ID. When i do postback i can access the controls themselves and the ID's that i gave them, but i cannot access the value of the textbox (.Text property)which contains the user input. I have searched Google for examples of dynamic controls but all of them display when a value is set programmatically by the programmer, not the User input.So my question is, why cant i access the values?Can the User input at all be fetched? Any sug...

cant get web user control page value
i have a page web user control (ascx file), name =criteria in the ascx page i have a dropdownlist, name = Field1 the ascx page have a function Function GetValue() as string    Return Field1.SelectedItem.text Ebd Function now i include the ascx file to my web form with button ''''button at the web form not ascx file in button click events Dim Str as String Dim objCriteria as new Criteria  ' Criteria is ascx page class name Str = objCriteria.GetValue But at runtime i get an error say null reference exception how to solve the problem? i using VS 2005 and .ne...

Problem in accessing web form data in user controls when create user control dynamically
HI. I have a problem using web user control. I designed a user control named NewsForm. This user control contains some web form elements like <asp:textbox>. When I add it in an .ASPX page, all things may be true. I can know which user filles in textbox (for example and other controls) <%@ Register TagPrefix="uc1" TagName="NewsForm" Src="NewsForm.ascx" %> and <UC1:NewsForm id="newsForm" runat="server"></UC1:NewsForm> But when i create it in code behined dynamically, however user control has web form controls but their value are blank for example //aspx co...

How to get the value of dynamically created text box which is created dynamically on click of button control.
<p>Dear AllI am new in asp.net.I am doing one project there I have one doubt.what I want is I have taken two  button controls in my page, in click of first button1 I have  dynamically created one textbox and I added this textbox to my page and also set the id for this textbox,.after that in click of second button2 I want that the value of the textbox will be print in my page by getting the value of the textbbox. some codes are given below. <form id="form1" runat="server">    <div>      ...

Getting user selected value of Dynamic created Rating control
I ve a  pg in which i m creating 5 rating controls dynamically, i ve placed them inside placeholder. code is given below  //Page_Load for(i=0;i<4;i++) { Rating r = new Rating(); r.ID = "Ratingcontrol" + counter.ToString(); r.CurrentRating = 0;  r.MaxRating = 5; r.StarCssClass = "ratingStar"; r.WaitingStarCssClass = "savedRatingStar"; r.EmptyStarCssClass = "emptyRatingStar"; r.FilledStarCssClass = "filledRatingStar"; r.RatingDirection = RatingDirection.LeftToRightTopToBottom; r.EnableViewState = true; PlaceHolder1.Controls.Add(r); r.Visible = true; Place...

UserControl ? Dynamically create Usercontol AND get variable value from usercontrol to another user control
Hi Guys,  I quite new to Asp. net C#, but i need to know how to handle usercontrol. IntroductionMyUserControl1 -> connect to db and display values in gridviewMyUserContol2 -> Need to use the variable in MyUserControl1 Questions 1) I need to dynamically create MyUserControl1 IN MyUserConrtol1 and load it to my MasterPage (Report.aspx). MyUserControl1 will create the no. of usercontrol base on the record rows retrieved. Is ther another way to do it? 2) Next in MyUserControl2 would need to use  a  variable (uc1Variable)  in MyUserControl1is it po...

Reading form values in dynamically created child controls in a user control
I have a common problem for which I've searched the web for answers for hours to no avail. I have some radiobuttonlists ,dropdownlists,checkboxlists and text controls in a user control. The lists are created statically, however the items in the lists are populated at run time. The lists are displayed in default.aspx (the containing page) and populated on the Page_Load event of the user control .ascx file based on an external data source containing arrays of data. I want to be able to read the values selected by the user from deafult.aspx, the parent page. details: The .ascx...

Dynamically Loading User Control and Maintaining its viewstate. And Getting Values from the control.
 I have a drop down which is populated on the page looad.  When i select an item from drop downlist i get to see two listboxes with add/removing the objects from one left to right listbox and below that i have a user control which should be populated dynamically based on the selectedvalue from drop down list.  So there are three sections that are seen once a selected value is consiedered from drop down list.  Now I am getting the user control using the below code givencase "42": viewRequired = "vw_AncCostSavingsByCarrier_adhoc";    ...

Getting the Selected Item of dropdownlist inside Web User Control on a Web Form
Ive got a dropdownlist control inside a web user control called Entity.ascx. This web user control is on a webform.aspx. In Entity.ascx class I created a SelectedEntity property that returns the selected item in the dropdownlist. Inside webform.aspx when btnGo is pushed I set a string and pass it in the url. I am trying to get the entity they selected via the property (SelectedEntity) inside Entity.ascx. As the SelectedEntity property tries to return the selected item in the dropdownlist I get this error: System.NullReferenceException: Object reference not set to an instance...

User Control controls not created when dynamically creating user control
  Have created a user control for displaying and editing a dynamically number of values. The user control contains two labels and an edit box. When dynamically loading the user control I get an error when the control itself tries to change setting on the fields within the user control.   Why doesnt this work? It works okay if I dont load it dynamically but create a user-control-instance in the aspx-page but thats no solution.   Thankyou!     Here is my code:   ucDataValue.ascx   <%@ Control Language="C#" AutoEventWireup="true&...

Creating dynamic controls and getting their values
 Hi everyone,i have to create a number of dynamic controls (dropdownlist and textboxes) acording to a number inputed by the user.i've read some articles, posted some posts, but aynone has truly help me, so i'm asking if someone can hepl me beeing objective.i've put the code in the page_load, and in the the page_init (not on both simultaneous), but i don't know in which one is right.The code i putted on the Page_Load was this:Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load        If (Page.IsPo...

Get the value of dynamically created controls
I have created the following function to get the text out of dynamically created text boxes that I have created from the code behind page.When call the function I get a message saying Object Reference not set to an instance of an object on this line -For Each c In Me.Parent.ControlsThe ID of the textboxes have the following format - Quantity_1111 Private Sub btnUpdate_Click(ByVal sender As System.Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles btnUpdate.Click Dim c As Control Dim strID As String Dim arrProducts(2) As String Dim dtProducts As New DataTable 'Dim parent As C...

Get values of dynamic created controls?
Hello there,I'm creating some dynamic controls, where i'm getting some info from a db. - Thats working, but I dont know how to get the values from the dynamic created controls again, so i could save them in my database? This code am i using to create the controls (This get looped for each record in the db) 1 ' Connection 2 Dim str As String = System.Web.Configuration.WebConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString 3 Dim conn As SqlConnection = New SqlConnection(str) 4 conn.Open(...

Web resources about - Get user input from dynamic created control, why i cant get the value??? - asp.net.web-forms

Donald Trump To Ring In 2016 On Fox News
Donald Trump will help ring in the New Year on Fox News Channel . The GOP Presidential candidate will join The Five ‘s Kimberly Guilfoyle and ...

The remarkable story of the World War II 'Ghost Army' that duped Hitler
From the summer of 1944 till the end of the war in Europe, the US fielded a unique 'Ghost Army' throughout France and the Rhine Valley in order ...

Experts applaud SpaceX rocket landing, potential savings
CBS News Experts applaud SpaceX rocket landing, potential savings CBS News The successful launch and landing by the first stage of a SpaceX ...

Iraqi forces storm last ISIS stronghold in Ramadi to push them out
Iraq's armed forces today stormed the last Islamic State stronghold in central Ramadi in a bid to retake the city that it lost in an embarrassing ...

Over one million migrants reach Europe in 2015: UN
A vast majori­ty of people, 821,008, landed in Greece, while 3,692 migran­ts died or disapp­eared crossi­ng the sea

Subscription Boxes: The Hottest Craze For Last Minute Christmas Gifts
Subscription boxes are the latest hot craze for last minute gift giving. Looking for a special gift for the woman in your life? How about for ...

R/GA Says Goodbye to 30-Year Headquarters in Tribute Video
When R/GA founder, chairman and CEO Bob Greenberg was traveling for a week, staffers took it upon themselves to create a tribute video for him ...

Miss Germany apologises after sparking outrage by slamming Miss Universe winner, claiming 'none of us ...
The event ended up running far from smoothly after Steve Harvey fluffed the results in front of a live audience and millions watching at home ...

Prosecutor denies accusations by Sandra Bland's family: 'I'm begging to meet ...
Chicago Tribune Prosecutor denies accusations by Sandra Bland's family: 'I'm begging to meet ... Chicago Tribune Geneva Reed-Veal, left, and ...

Watch Gwen Stefani & Blake Shelton In Sweet Kissing Session: Country Crooner Charms Her Kids As Romance ...
Blake Shelton and Gwen Stefani are piling on the PDA to disprove all those who claimed that their romance on The Voice was just showmance for ...

Resources last updated: 12/22/2015 8:49:19 PM