asp.net - VB.net Findcontrol Not Working -
simple findcontrol not working - kicking back:
system.nullreferenceexception: object reference not set instance of object.
i've got asp.net label on web page.
<asp:label id="lblmenuitemname1" runat="server" text="label"></asp:label>
the label control not inside other control (datagrid, repeater, etc). calling code on button click.
dim lblmenuitemname label lblmenuitemname = ctype(page.findcontrol("lblmenuitemname1"), label) lblmenuitemname.text = "hello"
i've tried (and half dozen of scenarios):
lblmenuitemname = findcontrol("lblmenuitemname1") lblmenuitemname = me.findcontrol("lblmenuitemname1")
i'm doing this, instead of referencing control directly, because i've got ten of these labels , i'm going assign text through loop using
findcontroll("lblmenuitemname" & x.tostring)
fyi - referencing control directly works fine.
lblmenuitemname1.text = "hello"
where going wrong?
update: i've discovered problem (thanks comments below) problem control in content control. looking find out how reference label within content control. like:
dim x content = me.findcontrol("content3") dim lblmenuitemname label = x.findcontrol("lblmenuitemname1") lblmenuitemname.text = "hello" <asp:content id="content3" contentplaceholderid="contentbody" runat="server"> <asp:label id="lblmenuitemname1" runat="server" text="label"></asp:label><br /><br /> <asp:button id="button1" runat="server" text="button" />
after several hours , dozens of trial , error, here looking for:
dim lblmenuitemname label = trycast(master.findcontrol("contentbody").findcontrol("lblmenuitemname1"), label)
Comments
Post a Comment