Solved

grabbing text from panel

Posted on 2013-12-04
3
249 Views
Last Modified: 2013-12-05
I'm trying to grab text from a panel, but I can't figure out how to do it. I put the data in the panel using  this format.

var PosTo = (Query).SingleOrDefault();

Panel1.Controls.Add(new LiteralControl(PosTo.Data));

Open in new window

I'm now trying to grab that data.

I've tried the code below but I get "An exception of type 'System.ArgumentOutOfRangeException' occurred in System.Web.dll but was not handled in user code"

var panelContent = ((Panel)Panel1).Controls[0] as LiteralControl;

Open in new window


What am I doing wrong?
0
Comment
Question by:NickMalloy
  • 2
3 Comments
 
LVL 14

Accepted Solution

by:
Dustin Hopkins earned 350 total points
ID: 39697670
Where is the second bit of code being called? I was unable to replicate the error using the following code
 protected void Page_Load(object sender, EventArgs e)
        {
            const string str = "Some string info";
            Panel1.Controls.Add(new LiteralControl(str));

        }

        protected void Button1_Click(object sender, EventArgs e)
        {
           
            var panelContent = Panel1.Controls[0] as LiteralControl;
            Label1.Text = panelContent.Text;
            Label1.Text += " SecondCall:" + ((LiteralControl)Panel1.Controls[0]).Text;
        }

Open in new window


Are you sure the panel has the control in it when the second item is being called? Because that error is saying that there are no controls in the panel, also I was unable to replicate the error when adding a literal control null text.

Hope this helps,
Dustin
0
 

Author Comment

by:NickMalloy
ID: 39698250
The Second bit of code is being called from a gridview's rowdatabind function. The other code is in the page load function.
0
 

Author Comment

by:NickMalloy
ID: 39698550
found the problem. Bound the gridview before the panel.
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Explain Unit of Work pattern 2 47
Asp/Net Validation date Issue 9 37
Trouble with References... 5 22
Jquery autocomplete 10 23
Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now