FindControl()

Godlab

New Member
I have a DataGrid that contains rows with template columns. On the "Update" event, I call a certain subprocedure. Inside that sub, I am trying to retrieve the values of certain controls within the row which may have been modified during the "Edit" mode.<BR><BR>I use the following syntax to do this:<BR><BR>'''''''''''''''''''''''''''''''''''''''''''''''''' '<BR>sub MyUpdateSub(sender As Object, e As DataGridCommandEventArgs)<BR>dim sValue as string<BR>'Grab the current value of my textbox control<BR>sValue = http://aspmessageboard.com/archive/index.php/e.Item.FindControl("txtMyTextBox").Text()<BR>...<BR>end sub<BR>'''''''''''''''''''''''''''''''''''''''''''''''''' '<BR><BR>If I do it that way, an error is produced, saying that "Text()" is not a valid member of the "Controls" class.<BR><BR>Now, if I check the type of object returned by the "FindControl()" method (e.Item.FindControl("txtMyTextBox").ToString()) it tells me that I *do* have a TextBox object. Should I not then be able to access the Text() property of the TextBox?<BR><BR>I have also tried the following approach:<BR><BR>''''''''''''''''''''''''''''''''''''<BR>sub MyUpdateSub(sender As Object, e As DataGridCommandEventArgs)<BR>dim txtBox as textbox<BR>dim sValue as string<BR><BR>txtBox = e.Item.FindControl("txtMyTextBox")<BR>sValue = txtBox.Text()<BR>...<BR>end sub<BR>''''''''''''''''''''''''''''''''''''<BR><BR>This does not produce any error and when I check the ID of the new textbox (txtBox.ID()) to make sure that it is truly a copy of the original, it returns the ID of the original as I would hope.<BR><BR>However, the Text() property always comes out as the original value displayed by the textbox in the datagrid, not as the modified value of the textbox.<BR><BR>So, my two questions are,<BR><BR>1. Why can't I directly access the properties/methods of an object returned by FindControl()?<BR><BR>2. Why am I not getting the modified values of the controls sent to the update sub, but rather their original values?<BR><BR>Thank you so much for your help and patience.I did a search on this messageboard to see if anyone else has had the same question as I've had. I didn't know I could do that until this morning. I found that another gentleman did have the same problem as I do and no one answered his question either.<BR><BR>His question can be found at: http://www.aspmessageboard.com/forum/showMessage.asp?F=36&M=175608&P=1<BR><BR>Is there a way to accomplish what he and I are trying to do?When I need to do basicly the same thing, I have never accully dimed txtBox, I just let it create it on the fly as a type variant. I know it's not the best method, but it works. Also, try txtBox.text without the (), that's the way it is in all of my code and it works. Good luck.Thank you, Valsacar. I tried what you suggested, but it didn't work.<BR><BR>I don't understand why it shouldn't work. My code is written exactly according to the code samples I've seen that supposedly work. I've only encountered one other instance where someone is having the same type of problem as mine and he hasn't had his questions answered either. It's a mystery!<BR><BR>I just don't know why I can't directly access the members of an object retrieved by "FindControl()". Logically, it should work but it doesn't. I hope this is something that will be fixed in Beta 2 or later versions of the framework.<BR><BR>Thank you for your help.
 
Back
Top