making control on run-time from a to z
-
hi i want to create the labels,comboxes, text boxes etc all on run time... i.e. EVEN THEIR NAMES are created on runtime...cause i dont know how many of them will be created.. it all happens in a loop and every loop creates a label and a combobox and a textbox and is created all with different names..even names are MADE on runtime.... hope someone can help...tks.. i know how to make controls on run-time where i provide the names like Label myLabel = new Label(); here i already provide the names.. but what i am looking ofr is that i want to MAKE the names during runtime and GIVE those names to the controls to create them... tks.. "Rejoice always, pray without ceasing, in everything give thanks; for this is the will of God in Christ Jesus for you."1Thess. 5:16-18
-
hi i want to create the labels,comboxes, text boxes etc all on run time... i.e. EVEN THEIR NAMES are created on runtime...cause i dont know how many of them will be created.. it all happens in a loop and every loop creates a label and a combobox and a textbox and is created all with different names..even names are MADE on runtime.... hope someone can help...tks.. i know how to make controls on run-time where i provide the names like Label myLabel = new Label(); here i already provide the names.. but what i am looking ofr is that i want to MAKE the names during runtime and GIVE those names to the controls to create them... tks.. "Rejoice always, pray without ceasing, in everything give thanks; for this is the will of God in Christ Jesus for you."1Thess. 5:16-18
I'm not sure if you have t set its ID,cause MAYBE ASP.NET add it automaticlly, but if you need it, you can compose a name with control+number and start number from specific number 1000 so you will have something le this: control1000,control1001,control1002,... Mazy You're face to face, With the man who sold the world - David Bowie
-
I'm not sure if you have t set its ID,cause MAYBE ASP.NET add it automaticlly, but if you need it, you can compose a name with control+number and start number from specific number 1000 so you will have something le this: control1000,control1001,control1002,... Mazy You're face to face, With the man who sold the world - David Bowie
but the prob is when i do this
dim name as string for i = 1 to 100 name = "control" & i.ToString(somehting like..u know hwat i mean) 'now we have name = say, control1000 now name = new label()
now istead of assigning control1000 as the name of the control, it assigns name as the name for the label.. thats my prob... can u pls help..?? tks.. "Rejoice always, pray without ceasing, in everything give thanks; for this is the will of God in Christ Jesus for you."1Thess. 5:16-18 -
but the prob is when i do this
dim name as string for i = 1 to 100 name = "control" & i.ToString(somehting like..u know hwat i mean) 'now we have name = say, control1000 now name = new label()
now istead of assigning control1000 as the name of the control, it assigns name as the name for the label.. thats my prob... can u pls help..?? tks.. "Rejoice always, pray without ceasing, in everything give thanks; for this is the will of God in Christ Jesus for you."1Thess. 5:16-18First off, learn how to write better pseudocode, so we can tell exactly what you intend to do. Second, my best guess is that you are trying to do this:
For items As Integer = 1 To 100
Dim nextLabel As New Label
nextLabel.Text = "This is control number " + items.ToString()
nextLabel.ID = "Control" + items.ToString()
Page.Controls.Add(nextLabel)
Page.Controls.Add(New LiteralControl("<br>"))
NextWhat a piece of work is man, how noble in reason, how infinite in faculties, in form and moving how express and admirable . . . and yet to me, what is this quintessence of dust? -- Hamlet, Act II, Scene ii.
-
First off, learn how to write better pseudocode, so we can tell exactly what you intend to do. Second, my best guess is that you are trying to do this:
For items As Integer = 1 To 100
Dim nextLabel As New Label
nextLabel.Text = "This is control number " + items.ToString()
nextLabel.ID = "Control" + items.ToString()
Page.Controls.Add(nextLabel)
Page.Controls.Add(New LiteralControl("<br>"))
NextWhat a piece of work is man, how noble in reason, how infinite in faculties, in form and moving how express and admirable . . . and yet to me, what is this quintessence of dust? -- Hamlet, Act II, Scene ii.
yea..i was..tks... but another tougher prob arises when i do as your code... now the values are stored in those textboxes... but now lets say i wanna retrieve all the values when the user clicks a button and put it inside an array... i can write a forloop but then how can i do this
for i = 0 to arrthings.count()-1 arr1.add("val" & i, ???)'**how can i put the values of textboxes inside?? '**rangin from txtbx1 to txtbx7? next
can u pls tell me how i can do that??? tks a lot.. really appreciate your effort and help... sory for not being articulate.. "Rejoice always, pray without ceasing, in everything give thanks; for this is the will of God in Christ Jesus for you."1Thess. 5:16-18 -
yea..i was..tks... but another tougher prob arises when i do as your code... now the values are stored in those textboxes... but now lets say i wanna retrieve all the values when the user clicks a button and put it inside an array... i can write a forloop but then how can i do this
for i = 0 to arrthings.count()-1 arr1.add("val" & i, ???)'**how can i put the values of textboxes inside?? '**rangin from txtbx1 to txtbx7? next
can u pls tell me how i can do that??? tks a lot.. really appreciate your effort and help... sory for not being articulate.. "Rejoice always, pray without ceasing, in everything give thanks; for this is the will of God in Christ Jesus for you."1Thess. 5:16-18An article here[^] on CP describes how to maintain state for dynamically created controls. The article is in C#, but it's not hard to convert to VB. What a piece of work is man, how noble in reason, how infinite in faculties, in form and moving how express and admirable . . . and yet to me, what is this quintessence of dust? -- Hamlet, Act II, Scene ii.
-
An article here[^] on CP describes how to maintain state for dynamically created controls. The article is in C#, but it's not hard to convert to VB. What a piece of work is man, how noble in reason, how infinite in faculties, in form and moving how express and admirable . . . and yet to me, what is this quintessence of dust? -- Hamlet, Act II, Scene ii.
the article you gave me is what you already taught me....:) i am looking for the part to retrieve data from the dynamically created controls dynamically... any ideas? "Rejoice always, pray without ceasing, in everything give thanks; for this is the will of God in Christ Jesus for you."1Thess. 5:16-18
-
the article you gave me is what you already taught me....:) i am looking for the part to retrieve data from the dynamically created controls dynamically... any ideas? "Rejoice always, pray without ceasing, in everything give thanks; for this is the will of God in Christ Jesus for you."1Thess. 5:16-18
Hey, shouting is not necessary! ;) The point of the article is that if you generate some controls dynamically, send it to the user, and the page is posted back to the server, you need to re-generate the same controls with the same ID's in order to access the values of the dynamically created controls in the post back handler. What a piece of work is man, how noble in reason, how infinite in faculties, in form and moving how express and admirable . . . and yet to me, what is this quintessence of dust? -- Hamlet, Act II, Scene ii.
-
Hey, shouting is not necessary! ;) The point of the article is that if you generate some controls dynamically, send it to the user, and the page is posted back to the server, you need to re-generate the same controls with the same ID's in order to access the values of the dynamically created controls in the post back handler. What a piece of work is man, how noble in reason, how infinite in faculties, in form and moving how express and admirable . . . and yet to me, what is this quintessence of dust? -- Hamlet, Act II, Scene ii.
i am sorry, i wasnt shouting..:( i got it already.... you already told me that... now the thing is i want to retrieve the values... all is done, but my values are stuck....:( i cant seem to get it back dynamically...:( these are my code.
' This routine creates the controls and assigns a generic ID Private Sub createControls(ByVal arrList As ArrayList) Dim count As Integer = Me.NumberOfControls Dim i As Integer For i = 0 To count Dim myLabel As Label = New Label ' Set the label's Text and ID properties. myLabel.Text = arrList.Item(i) & " : " myLabel.ID = "Label_" & i.ToString() Page.Controls.Add(myLabel) 'Add a spacer in te form of an HTML element Dim tab As LiteralControl = New LiteralControl(" ") Dim myTextBox As TextBox = New TextBox 'Set the textbox's Text and ID properties myTextBox.Text = "" myTextBox.ID = "TextBox_" & i.ToString() Page.Controls.Add(myTextBox) ' Add a spacer in the form of an HTML element Dim spacer As LiteralControl = New LiteralControl(" ") Page.Controls.Add(spacer) Next 'Session.Add("NoOfRecords", i) 'Dim j As Integer 'Dim temp As String = ("label" & i.ToString()) & ".Text" 'i.ToString() myPlaceHolder.Visible = True lblInfo.Visible = True imgBtnSelectReport.Visible = True imgBtnRetrieveReport.Visible = True Session.Add("FilterArray", arrList) ddlReportCat.Enabled = False End Sub 'createControls
i am trying to write a for loop to access all the caontrol values.. but i dont know how many vales are there to access... :( i dont seem to be able to write the for loop... can you pls help... tks a lot... "Rejoice always, pray without ceasing, in everything give thanks; for this is the will of God in Christ Jesus for you."1Thess. 5:16-18 -
i am sorry, i wasnt shouting..:( i got it already.... you already told me that... now the thing is i want to retrieve the values... all is done, but my values are stuck....:( i cant seem to get it back dynamically...:( these are my code.
' This routine creates the controls and assigns a generic ID Private Sub createControls(ByVal arrList As ArrayList) Dim count As Integer = Me.NumberOfControls Dim i As Integer For i = 0 To count Dim myLabel As Label = New Label ' Set the label's Text and ID properties. myLabel.Text = arrList.Item(i) & " : " myLabel.ID = "Label_" & i.ToString() Page.Controls.Add(myLabel) 'Add a spacer in te form of an HTML element Dim tab As LiteralControl = New LiteralControl(" ") Dim myTextBox As TextBox = New TextBox 'Set the textbox's Text and ID properties myTextBox.Text = "" myTextBox.ID = "TextBox_" & i.ToString() Page.Controls.Add(myTextBox) ' Add a spacer in the form of an HTML element Dim spacer As LiteralControl = New LiteralControl(" ") Page.Controls.Add(spacer) Next 'Session.Add("NoOfRecords", i) 'Dim j As Integer 'Dim temp As String = ("label" & i.ToString()) & ".Text" 'i.ToString() myPlaceHolder.Visible = True lblInfo.Visible = True imgBtnSelectReport.Visible = True imgBtnRetrieveReport.Visible = True Session.Add("FilterArray", arrList) ddlReportCat.Enabled = False End Sub 'createControls
i am trying to write a for loop to access all the caontrol values.. but i dont know how many vales are there to access... :( i dont seem to be able to write the for loop... can you pls help... tks a lot... "Rejoice always, pray without ceasing, in everything give thanks; for this is the will of God in Christ Jesus for you."1Thess. 5:16-18my prob is that i cant get the values from the generated controls... i know the no of controls that are generated.. i know that i want the values of the textboxes generated but i cant get the values... :( lets say i have TextBox_1 TextBox_2 TextBox_3 TextBox_4 i know the number of the textboxes so i am able to address them but when it comes to retrieve the values comes the prob.. lets say i write the loop to retrieve the values
for i=0 to NoOfControls() dim ans as string = '*Here i want the value of TextBox_1.Text, TextBox_2.Text,TextBox_3.Text,TextBox_4.Text 'but i cant seem to assign it that way.. dim ans as string = ("TextBox_" + i).Text ???? it gives me error :( 'pls help... next
hope you can help.... tks "Rejoice always, pray without ceasing, in everything give thanks; for this is the will of God in Christ Jesus for you."1Thess. 5:16-18 -
my prob is that i cant get the values from the generated controls... i know the no of controls that are generated.. i know that i want the values of the textboxes generated but i cant get the values... :( lets say i have TextBox_1 TextBox_2 TextBox_3 TextBox_4 i know the number of the textboxes so i am able to address them but when it comes to retrieve the values comes the prob.. lets say i write the loop to retrieve the values
for i=0 to NoOfControls() dim ans as string = '*Here i want the value of TextBox_1.Text, TextBox_2.Text,TextBox_3.Text,TextBox_4.Text 'but i cant seem to assign it that way.. dim ans as string = ("TextBox_" + i).Text ???? it gives me error :( 'pls help... next
hope you can help.... tks "Rejoice always, pray without ceasing, in everything give thanks; for this is the will of God in Christ Jesus for you."1Thess. 5:16-18Dude, you're forcing me to write a bunch of code to show you how this works. ;)
Public Class DynamicControlsPage
Inherits System.Web.UI.Page' details omitted... ' Modifications of Mads Nissen's code for article "Retaining State for Dynamically Created Controls in ASP.NET applications" Private Sub Page\_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load If Not IsPostBack Then NumberOfControls = 0 Else ReCreateControls() End If End Sub Protected Property NumberOfControls() As Integer Get Return CType(ViewState("NumControls"), Integer) End Get Set(ByVal Value As Integer) ViewState("NumControls") = Value End Set End Property Private Sub ReCreateControls() For i As Integer = 1 To Me.NumberOfControls Dim tx As New TextBox tx.ID = "TextBox\_" + i.ToString() phTextBoxes.Controls.Add(tx) Next End Sub Private Sub cmdAddControls\_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdAddControls.Click For i As Integer = 1 To 10 Dim tx As New TextBox tx.ID = "TextBox\_" + i.ToString() phTextBoxes.Controls.Add(tx) NumberOfControls += 1 Next End Sub Private Sub cmdDisplayValueFive\_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdDisplayValueFive.Click Dim tx As TextBox = CType(Page.FindControl("TextBox\_5"), TextBox) txtValueDisplay.Text = tx.Text End Sub
End Class
So, the answer to your question lies in the
cmdDisplayValueFive_Click
method outlined above. What a piece of work is man, how noble in reason, how infinite in faculties, in form and moving how express and admirable . . . and yet to me, what is this quintessence of dust? -- Hamlet, Act II, Scene ii. -
Dude, you're forcing me to write a bunch of code to show you how this works. ;)
Public Class DynamicControlsPage
Inherits System.Web.UI.Page' details omitted... ' Modifications of Mads Nissen's code for article "Retaining State for Dynamically Created Controls in ASP.NET applications" Private Sub Page\_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load If Not IsPostBack Then NumberOfControls = 0 Else ReCreateControls() End If End Sub Protected Property NumberOfControls() As Integer Get Return CType(ViewState("NumControls"), Integer) End Get Set(ByVal Value As Integer) ViewState("NumControls") = Value End Set End Property Private Sub ReCreateControls() For i As Integer = 1 To Me.NumberOfControls Dim tx As New TextBox tx.ID = "TextBox\_" + i.ToString() phTextBoxes.Controls.Add(tx) Next End Sub Private Sub cmdAddControls\_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdAddControls.Click For i As Integer = 1 To 10 Dim tx As New TextBox tx.ID = "TextBox\_" + i.ToString() phTextBoxes.Controls.Add(tx) NumberOfControls += 1 Next End Sub Private Sub cmdDisplayValueFive\_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdDisplayValueFive.Click Dim tx As TextBox = CType(Page.FindControl("TextBox\_5"), TextBox) txtValueDisplay.Text = tx.Text End Sub
End Class
So, the answer to your question lies in the
cmdDisplayValueFive_Click
method outlined above. What a piece of work is man, how noble in reason, how infinite in faculties, in form and moving how express and admirable . . . and yet to me, what is this quintessence of dust? -- Hamlet, Act II, Scene ii.really really appreciate your help and your effort Mr.John... one last question pls if i do this :
dim tx as TextBox = CType(Page.FindControl("TextBox_" & i.ToString),TextBox)
will it still work?? tks a lot... Mr.John... :) really really appreciate your help... :) tk you so much..:) "Rejoice always, pray without ceasing, in everything give thanks; for this is the will of God in Christ Jesus for you."1Thess. 5:16-18 -
really really appreciate your help and your effort Mr.John... one last question pls if i do this :
dim tx as TextBox = CType(Page.FindControl("TextBox_" & i.ToString),TextBox)
will it still work?? tks a lot... Mr.John... :) really really appreciate your help... :) tk you so much..:) "Rejoice always, pray without ceasing, in everything give thanks; for this is the will of God in Christ Jesus for you."1Thess. 5:16-18 -
Yup, that's the general idea. Happy coding! What a piece of work is man, how noble in reason, how infinite in faculties, in form and moving how express and admirable . . . and yet to me, what is this quintessence of dust? -- Hamlet, Act II, Scene ii.
tks Mr.Kuhn.... appreciate your help :) "Rejoice always, pray without ceasing, in everything give thanks; for this is the will of God in Christ Jesus for you."1Thess. 5:16-18