Forum Moderators: open

Message Too Old, No Replies

help me prove my reference book is incorrect

they might not have option strict on

         

mattglet

8:52 pm on May 30, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



in my asp.net reference book that i'm using to learn this language (i'm not going to list the actual title... not sure if it's against TOS), they show this example:


dim EditText as Textbox
EditText = E.Item.FindControl("txtBlah")

when i enter that into my code (of which i have Option Strict turned on), i get this error:
"Option Strict On disallows implicit conversions from 'System.Web.UI.Control' to 'System.Web.UI.WebControls.Textbox'."

i am referencing values from a datagrid, and using FindControl to pull the values to then add to my datatable. do the writers of my book not use Option Strict in this example, or am i doing something wrong?

-Matt

sharbel

3:17 am on May 31, 2003 (gmt 0)

10+ Year Member



Not sure in VB.NET but in C# that code shouldnt compile since you cant implicity cast a Control to a TextBox.. for that code to compile you would have to do this:

TextBox editBox;
editBox = (TextBox)e.Item.FindControl("txtBlah");

So yeah, I would imagine that you are correct.

Xoc

8:06 am on May 31, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



That's right. The authors have Option Strict off. With Option Strict on, you have to do:


Dim EditText as Textbox
EditText = CType(E.Item.FindControl("txtBlah"), Textbox)

or slightly more efficient:

Dim EditText as Textbox
EditText = DirectCast(E.Item.FindControl("txtBlah"), Textbox)

BTW, no problem listing the title of the book! Just don't link to Barnes and Noble or Amazon with your affliate code.

mattglet

2:53 pm on Jun 2, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



xoc-

worked as you described, thank you.

now i have a new problem... when i use FindControl, it pulls the original value of the textbox, and saves THAT (as opposed to using the updated textbox value). but if i use Request.Form.Item(3).ToString, it works perfectly. any idea why FindControl isn't working?

yes, it's totally off the wall, and should not be happening this way, i know this :)

-Matt