-
Apr 16th, 2012, 01:50 PM
#1
FindControl + Casting Results In NullReferenceException
I'm using a third party control called an Accordion from Juice UI. Within that control, I have a table with labels.
VB.NET Code:
<juice:Accordion ID="accSwrlHddRepl" runat="server"> <juice:AccordionPanel runat="server" Title="HDD Information"> <PanelContent> <p> <table style="width: 99%;"> <tr> <td class="style2"> <asp:Label ID="Label2111111" runat="server" Text="Original HDD:"></asp:Label> </td> <td> <asp:Label ID="lblOriginalHDD" runat="server" Text="N/A"></asp:Label> </td> </tr> <tr> <td class="style2"> <asp:Label ID="Label16666666" runat="server" Text="First HDD Replacement:"></asp:Label> </td> <td> <asp:Label ID="lblFirstHddReplacement" runat="server" Text="N/A"></asp:Label> </td> </tr> <tr> <td class="style2"> <asp:Label ID="Label39876" runat="server" Text="Second HDD Replacement:"></asp:Label> </td> <td> <asp:Label ID="lblSecondHddReplacement" runat="server" Text="N/A"></asp:Label> </td> </tr> </table> </p> </PanelContent> </juice:AccordionPanel> <juice:AccordionPanel runat="server" Title="Replace HDD(s)"> <PanelContent> </PanelContent> </juice:AccordionPanel> <juice:AccordionPanel runat="server" Title="SWRL Letter"> <PanelContent> </PanelContent> </juice:AccordionPanel> </juice:Accordion>
I can't access the label directly, so I'm trying to use the FindControl method to get it and set it's text property.
VB.NET Code:
CType(Me.accSwrlHddRepl.FindControl("lblFirstHddReplacement"), System.Web.UI.WebControls.Label).Text = "string"
But I get a NullReferenceException. So I moved the label outside of the table and put it just inside the accordion. The same behavior occurs. Then I gave the accordion panel an ID and did FindControl there, but the same issue occurs.
So I'm a little confused here.
Anyone have any ideas?
CodeBank contributions: Process Manager, Temp File Cleaner
Originally Posted by SJWhiteley
"game trainer" is the same as calling the act of robbing a bank "wealth redistribution"....
-
Apr 16th, 2012, 02:17 PM
#2
Hyperactive Member
Re: FindControl + Casting Results In NullReferenceException
you might need to use find control, within the control, like this:
Code:
dim myL as label = Me.accSwrlHddRepl.FindControl("accSwrlHddRepl").FindControl("lblFirstHddReplacement").
if this doesnt work, first try:
Code:
dim myL as label = Me.accSwrlHddRepl.FindControl("accSwrlHddRepl")
to see if you can get a handle on the control.
if i was able to help, rate my post!
-
Apr 16th, 2012, 02:34 PM
#3
Re: FindControl + Casting Results In NullReferenceException
Originally Posted by jasonwucinski
you might need to use find control, within the control, like this:
Code:
dim myL as label = Me.accSwrlHddRepl.FindControl("accSwrlHddRepl").FindControl("lblFirstHddReplacement").
if this doesnt work, first try:
Code:
dim myL as label = Me.accSwrlHddRepl.FindControl("accSwrlHddRepl")
to see if you can get a handle on the control.
So using FindControl on the Accordion and then on the AccordionPanel, still produced the error. I cast the Accordion control to a variable (as an accordion, of course, not a label) and that worked. So I'm able to get a handle to that control.
CodeBank contributions: Process Manager, Temp File Cleaner
Originally Posted by SJWhiteley
"game trainer" is the same as calling the act of robbing a bank "wealth redistribution"....
-
Apr 16th, 2012, 02:41 PM
#4
Hyperactive Member
Re: FindControl + Casting Results In NullReferenceException
can you add an id to
Code:
<juice:AccordionPanel runat="server" Title="HDD Information" id="someId">
and then try using find control on that, then on the label? (ie
Code:
Me.accSwrlHddRepl.FindControl("accSwrlHddRepl").FindControl("someId").FindControl("lblFirstHddReplacement")
if i was able to help, rate my post!
-
Apr 16th, 2012, 03:30 PM
#5
Re: FindControl + Casting Results In NullReferenceException
Originally Posted by jasonwucinski
can you add an id to
Code:
<juice:AccordionPanel runat="server" Title="HDD Information" id="someId">
and then try using find control on that, then on the label? (ie
Code:
Me.accSwrlHddRepl.FindControl("accSwrlHddRepl").FindControl("someId").FindControl("lblFirstHddReplacement")
I did that. Your first example:
Code:
Me.accSwrlHddRepl.FindControl("accSwrlHddRepl").FindControl("lblFirstHddReplacement")
Didn't make sense. You wanted me to call the main accordion's FinControl method to find itself and then find the label. I thought it was just a typo. So I put the ID of the panel in there. I mentioned in my first post that I gave it an ID.
Originally Posted by weirddemon
hen I gave the accordion panel an ID and did FindControl there, but the same issue occurs.
Code:
<juice:AccordionPanel runat="server" Title="HDD Information" ID="pnlHddInfo">
Code:
CType(Me.accSwrlHddRepl.FindControl("pnlHddInfo").FindControl("lblFirstHddReplacement"), Label).Text = "eeeeeeeeeee"
CodeBank contributions: Process Manager, Temp File Cleaner
Originally Posted by SJWhiteley
"game trainer" is the same as calling the act of robbing a bank "wealth redistribution"....
-
Apr 16th, 2012, 07:22 PM
#6
Re: FindControl + Casting Results In NullReferenceException
Hi.Can say that i've used that control but assuming that it has a namespace so you can reference it i made you an example of an ajax accordion.Your problem is that you do not take the <PanelContent> into consideration.Your label resides inside the <PanelContent> so here is what you can do in Ajax accordion and i think it will work if you can reference the juice AccordionPanel to expose it's objects:
Code:
Dim acp As AjaxControlToolkit.AccordionPane
acp = Me.FindControl("AccordionPane1")
Dim lbl1 As Label = acp.ContentContainer.FindControl("label1")
Dim str As String = lbl1.Text
ἄνδρα μοι ἔννεπε, μοῦσα, πολύτροπον, ὃς μάλα πολλὰ
πλάγχθη, ἐπεὶ Τροίης ἱερὸν πτολίεθρον ἔπερσεν·
-
Apr 17th, 2012, 03:35 PM
#7
Re: FindControl + Casting Results In NullReferenceException
Originally Posted by sapator
Hi.Can say that i've used that control but assuming that it has a namespace so you can reference it i made you an example of an ajax accordion.Your problem is that you do not take the <PanelContent> into consideration.Your label resides inside the <PanelContent> so here is what you can do in Ajax accordion and i think it will work if you can reference the juice AccordionPanel to expose it's objects:
Code:
Dim acp As AjaxControlToolkit.AccordionPane
acp = Me.FindControl("AccordionPane1")
Dim lbl1 As Label = acp.ContentContainer.FindControl("label1")
Dim str As String = lbl1.Text
The Juice Accordion panel doesn't have a ContentContainer class. But I understand what you're doing there, it just doesn't seem like the Juice control has that capability. Unless I'm confused.
If you want to test the Juice controls, it's really simple if you have NuGet for VS.
http://docs.nuget.org/docs/start-her...anager-console
CodeBank contributions: Process Manager, Temp File Cleaner
Originally Posted by SJWhiteley
"game trainer" is the same as calling the act of robbing a bank "wealth redistribution"....
-
Apr 17th, 2012, 06:37 PM
#8
Re: FindControl + Casting Results In NullReferenceException
Sorry i don't want to push my registry more but i could try to find out with the jquery accordion when i have the time and if i can make it work.
Also it's not obligatory for the AccordionPanel to have the ContentContainer object it may be a different name.You said you can reference it so what do you get when you press the dot on the AccordionPanel?Does anything in there seems to be useful?
ἄνδρα μοι ἔννεπε, μοῦσα, πολύτροπον, ὃς μάλα πολλὰ
πλάγχθη, ἐπεὶ Τροίης ἱερὸν πτολίεθρον ἔπερσεν·
-
Apr 17th, 2012, 06:50 PM
#9
Re: FindControl + Casting Results In NullReferenceException
Originally Posted by sapator
Sorry i don't want to push my registry more but i could try to find out with the jquery accordion when i have the time and if i can make it work.
Also it's not obligatory for the AccordionPanel to have the ContentContainer object it may be a different name.You said you can reference it so what do you get when you press the dot on the AccordionPanel?Does anything in there seems to be useful?
No need to apologize. I wasn't asking you to do anything. Only mentioned that you could if you wanted.
As for the intellisense, I forgot to mention that I did check it out.
I asked the same question at SO, but added details I neglected here.
CodeBank contributions: Process Manager, Temp File Cleaner
Originally Posted by SJWhiteley
"game trainer" is the same as calling the act of robbing a bank "wealth redistribution"....
-
Apr 18th, 2012, 12:54 AM
#10
Re: FindControl + Casting Results In NullReferenceException
Ok i feel better now :P
Hey can you tell us what exactly you need to do with the label?I was thinking that if what you try is on the client side then you porbably could work something with javascript instead of trying to hit the server.
ἄνδρα μοι ἔννεπε, μοῦσα, πολύτροπον, ὃς μάλα πολλὰ
πλάγχθη, ἐπεὶ Τροίης ἱερὸν πτολίεθρον ἔπερσεν·
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|