Wednesday, September 26, 2007

How not to access an asp.net Repeater control's data 

 

It would appear that between some .net updates Microsoft likes to change how Asp.net names controls.

>
For i As Integer = 0 To ilsn - 1       
 Dim controlname As String = "repGrid:_ctl" & i + 1 & ":txtOrder"
 Dim controlnameVal As Int32 = Request(controlname)
 StoreVal( ControlNameVal)
Next

This approach is safer

>
For Each di In repGrid.Items       
 Dim controlnameVal As Int32 = ConvertToINT( di.FindControl("txtOrder"))
 StoreVal( ControlNameVal)
Next

 

When your using an asp.net Repeater control you need to call find control on the given row in order for it to properly resolve the name.

Also of interest is this little nugget found on The Scripts forum:

.net Changing $ to _ ?

http://www.thescripts.com/forum/thread703070.html

ms went down a rat hole with names and ids. they started with ":" as

separator, but found this was illegal in an id or name, so replaced it

"$". then they realized "$" was illegal in an id when they wanted xhtml

compliance, so they changed it to "_" in an id.

posted by Aaron Fischer on Wednesday, September 26, 2007 2:05:47 PM (Pacific Standard Time, UTC-08:00)   #    Comments [0]