[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.dotnet.framework.aspnet.webcontrols

getting values of dynamically added controls

June Blasey

2/12/2004 6:03:00 PM

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
5 Answers

Teemu Keiski

2/12/2004 7:45:00 PM

0

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

2/12/2004 9:42:00 PM

0

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

=?Utf-8?B?cm9kY2hhcg==?=

2/13/2004 1:56:00 PM

0

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

2/13/2004 5:43:00 PM

0

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

2/17/2004 3:18:00 PM

0

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.develop... ***
Don't just participate in USENET...get rewarded for it!