html - How to get TagName of Control if exists? -


i have written code:

    if (alohaenabled)         dim head control = nothing         each control in master.controls             dim field = control.gettype.getfield("tagname")             if ((field isnot nothing) andalso (field.getvalue(control).equals("head")))                 'add aloha scripts             end if         next     end if 

if alohaenabled true, intend add links , scripts head tag. not know in advance kind of master used, therefore iterate controls , field called tagname through reflection. if field has value, compare "head" , if match, intend add aloha scripts (the question more general though, need different scripts or somewhere else). tagname field of system.web.ui.htmlcontrols.htmlcontrol. 0'th control in test case returns

{name = "htmlhead" fullname = "system.web.ui.htmlcontrols.htmlhead"} 

on control.gettype. if @ system.web.ui.htmlcontrols.htmlhead, see inherits system.web.ui.htmlcontrols.htmlgenericcontrol, on turn inherits system.web.ui.htmlcontrols.htmlcontainercontrol, inherits htmlcontrol. since tagname public, expect control.gettype.getfield("tagname") return "head". instead of that, returns nothing. wonder cause of behavior?

edit:

floatingkiwi right, problem was searching field, property, therefore did not find (what purpose of properties anyway, can resolve tasks methods). have used work-around in meantime:

        each control in master.controls             if (typeof control system.web.ui.htmlcontrols.htmlcontrol)                 dim htmlcontrol = ctype(control, system.web.ui.htmlcontrols.htmlcontrol)                 if (htmlcontrol.tagname.equals("head"))                     'add aloha scripts                 end if             end if         next 

i wonder superior solution: work-around, or property searching using reflection?

it's property not field. use

dim propinfo = control.gettype.getproperty("tagname") instead.

that return propertyinfo object. actual value use

dim result = propinfo .getvalue(control, nothing)


Comments

Popular posts from this blog

Spring Boot + JPA + Hibernate: Unable to locate persister -

go - Golang: panic: runtime error: invalid memory address or nil pointer dereference using bufio.Scanner -

c - double free or corruption (fasttop) -