Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   ASP .Net Web Controls (http://www.velocityreviews.com/forums/f63-asp-net-web-controls.html)
-   -   getting values of dynamically added controls (http://www.velocityreviews.com/forums/t772631-getting-values-of-dynamically-added-controls.html)

June Blasey 02-12-2004 06:03 PM

getting values of dynamically added controls
 
I am adding controls(dropdowns and checkboxes) dynamically to a placeholder or a htmltable control on a web form. I am able to load the page successfully. However, upon selecting a button(submit) on the page I am unable to get the values entered in the controls that were added. I can not even use the findcontrol method to find the controls.
Has anyone done this successfully? It seems to do with state?!?!?!
PLEASE, any ideas would be GREATLY APPRECIATED!!

Thanks,
June

___
Newsgroups brought to you courtesy of www.dotnetjohn.com

Teemu Keiski 02-12-2004 07:44 PM

Re: getting values of dynamically added controls
 
Hi,

do you add the controls to the PlaceHolder on postback as well? If you
don't, you need to do that as controls need to be recreated on postback for
them to keep state, be searchable (in other words exist in Controls
collection)

--
Teemu Keiski
MCP, Microsoft MVP (ASP.NET), AspInsiders member
ASP.NET Forum Moderator, AspAlliance Columnist


"June Blasey" <jblasey@yahoo.com> wrote in message
news:uj7UDKZ8DHA.2056@TK2MSFTNGP10.phx.gbl...
I am adding controls(dropdowns and checkboxes) dynamically to a placeholder
or a htmltable control on a web form. I am able to load the page
successfully. However, upon selecting a button(submit) on the page I am
unable to get the values entered in the controls that were added. I can not
even use the findcontrol method to find the controls.
Has anyone done this successfully? It seems to do with state?!?!?!
PLEASE, any ideas would be GREATLY APPRECIATED!!

Thanks,
June

___
Newsgroups brought to you courtesy of www.dotnetjohn.com



June Blasey 02-12-2004 09:42 PM

Re: getting values of dynamically added controls
 
Hey, Thanks. I am able to now access the controls. Will I also be able to get the value of selected item(s) in a dropdown list. Assuming a dropdown list is one of the dynamically added controls?

Thanks again,
June
>Hi,
>
> do you add the controls to the PlaceHolder on postback as well? If you
> don't, you need to do that as controls need to be recreated on postback for
> them to keep state, be searchable (in other words exist in Controls
> collection)
>
> --
> Teemu Keiski
> MCP, Microsoft MVP (ASP.NET), AspInsiders member
> ASP.NET Forum Moderator, AspAlliance Columnist
>
>
> "June Blasey" <jblasey@yahoo.com> wrote in message
> news:uj7UDKZ8DHA.2056@TK2MSFTNGP10.phx.gbl...
> I am adding controls(dropdowns and checkboxes) dynamically to a placeholder
> or a htmltable control on a web form. I am able to load the page
> successfully. However, upon selecting a button(submit) on the page I am
> unable to get the values entered in the controls that were added. I can not
> even use the findcontrol method to find the controls.
> Has anyone done this successfully? It seems to do with state?!?!?!
> PLEASE, any ideas would be GREATLY APPRECIATED!!
>
> Thanks,
> June
>
> ___
> Newsgroups brought to you courtesy of www.dotnetjohn.com
>
>
>


___
Newsgroups brought to you courtesy of www.dotnetjohn.com

josema 02-13-2004 01:56 PM

Re: getting values of dynamically added controls
 
Juney, how you solve that?, im getting the same problem since a long time...

I create controls dinamically but when i click the button, the controls dissapear, and i can get the values...

Thanks Juney.
Josema

Teemu Keiski 02-13-2004 05:43 PM

Re: getting values of dynamically added controls
 
Hi,

yes you are if you just add the Control to the Controls collection before
populating (populating happening on initial request).

e.g:
1. Create control instance
2. Add to Controls collection
3. populate inside IsPostBack check

Another solution is to populate before adding to the Controls collection (in
this case populating on every request). This way values are considered to be
initial values and aren't stored to ViewState, but on postback repopulation
happens before postback data processing, so actual selection can be kept.
( Control will save its state only after it is added to the Controls
collection, therefore first to the collection and then populating)

1. Create control instance
2. Populate on every request
3. Add to Controls collection

With some controls like DataGrid etc the latter will mix up with postback
events (databinding loses old state so events cannot be raised). With some
controls this latter one will work, but might be easier to use the first
one.

--
Teemu Keiski
MCP, Microsoft MVP (ASP.NET), AspInsiders member
ASP.NET Forum Moderator, AspAlliance Columnist


"June Blasey" <jblasey@yahoo.com> wrote in message
news:%23AcaQEb8DHA.2540@TK2MSFTNGP11.phx.gbl...
Hey, Thanks. I am able to now access the controls. Will I also be able to
get the value of selected item(s) in a dropdown list. Assuming a dropdown
list is one of the dynamically added controls?

Thanks again,
June
>Hi,
>
> do you add the controls to the PlaceHolder on postback as well? If you
> don't, you need to do that as controls need to be recreated on postback

for
> them to keep state, be searchable (in other words exist in Controls
> collection)
>
> --
> Teemu Keiski
> MCP, Microsoft MVP (ASP.NET), AspInsiders member
> ASP.NET Forum Moderator, AspAlliance Columnist
>
>
> "June Blasey" <jblasey@yahoo.com> wrote in message
> news:uj7UDKZ8DHA.2056@TK2MSFTNGP10.phx.gbl...
> I am adding controls(dropdowns and checkboxes) dynamically to a

placeholder
> or a htmltable control on a web form. I am able to load the page
> successfully. However, upon selecting a button(submit) on the page I am
> unable to get the values entered in the controls that were added. I can

not
> even use the findcontrol method to find the controls.
> Has anyone done this successfully? It seems to do with state?!?!?!
> PLEASE, any ideas would be GREATLY APPRECIATED!!
>
> Thanks,
> June
>
> ___
> Newsgroups brought to you courtesy of www.dotnetjohn.com
>
>
>


___
Newsgroups brought to you courtesy of www.dotnetjohn.com



June Blasey 02-17-2004 03:17 PM

Re: getting values of dynamically added controls
 
Thanks Teemu - I really appreciate you assistance.
Please forgive my ignorance. Below is a snipet of my code and how I am
adding the controls can you help me apply what you are saying about
creating the control, populating, then adding it??

Thanks again,
June
---------------
'Getting page layout and controls from database

SQL = "Select * from WebDSSSearch where SearchPage Like '" & SearchPage
& "' order by [Rw], [Col]"
SearchDA = New OleDb.OleDbDataAdapter(SQL, DSSConn)
SearchDA.Fill(SearchDS, "Search")
SearchTbl = SearchDS.Tables("Search")
NumRows = SearchTbl.Rows.Count
numcontrols = 0
If NumRows > 0 Then
SearchTable.Visible = True
Do While (I < NumRows) And (SearchTbl.Rows(I).Item("rw")
= PrevRow)
Dim sCell As New TableCell
ControlStr = Trim(SearchTbl.Rows(I).Item("Control"))

Select Case ControlStr
Case "ListBox"
Dim AClistlabel As New Label
AClistlabel.ID =
SearchTbl.Rows(I).Item("Fieldname")
sCell.Controls.AddAt(0, AClistlabel)

AClistlabel.Text =
SearchTbl.Rows(I).Item("Fieldname")
AClistlabel.Font.Size = FontUnit.XSmall
AClistlabel.Font.Bold = True
AClistlabel.Font.Name = "ariel"
AClistlabel.ForeColor = Color.Navy

Dim listDR As OleDb.OleDbDataReader
Query = SearchTbl.Rows(I).Item("DBMethod")


SqlCommand2.CommandText = Query
listDR = SqlCommand2.ExecuteReader

Dim AClist As New ListBox
AClist.ID =
Trim(SearchTbl.Rows(I).Item("ControlID"))
sCell.Controls.AddAt(1, AClist)

AClist.SelectionMode =
ListSelectionMode.Multiple
AClist.Rows = 2
AClist.DataSource = listDR
AClist.DataValueField =
Trim(SearchTbl.Rows(I).Item("DataField"))
AClist.DataBind()
listDR.Close()

sCell.ID = "cell" & I
numcontrols = numcontrols + 1
End Select
srow.Cells.Add(sCell)

PrevRow = SearchTbl.Rows(I).Item("rw")

Loop 'while row = prevrow
SearchTable.Rows.Add(srow)




*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!


All times are GMT. The time now is 05:03 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.