Solved

grabbing text from panel

Posted on 2013-12-04
3
253 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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

I have developed many web applications with asp & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
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.…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

786 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