Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

use variable name to set textbox readonly 1

Status
Not open for further replies.

drctx

IS-IT--Management
May 20, 2003
226
US
i've been stuck on this problem all day.
how can i use a variable name to set several textboxes to readonly?

Code:
While MyDataReader.Read

    if MyDataReader.Item("FieldType") Is System.DBNull.Value then
        ' do nothing
    else
        if MyDataReader.Item("FieldType") = "Hidden" then
            Page.FindControl("txt" + MyDataReader.Item("FieldName")).visible = false
            Page.FindControl("lbl" + MyDataReader.Item("FieldName")).visible = false
        end if

        if MyDataReader.Item("FieldType") = "ReadOnly" then
            Page.FindControl("txt" + MyDataReader.Item("FieldName")).readonly = true
            'txtShortDesc.readonly = true
        end if
    End If

End While
it gives the error:
'readonly' is not a member of 'System.Web.UI.Control'. on this line:
Code:
Page.FindControl("txt" + MyDataReader.Item("FieldName")).readonly = true
 
You need to get a refernce to the textbox with FindControl:
Code:
if MyDataReader.Item("FieldType") = "ReadOnly" then
   Dim txt as New TextBox
   txt = Page.FindControl("txt" + MyDataReader.Item("FieldName"))
   txt.readonly = true
end if

Jim
 
thank you very much! that made my day!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top