Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

grabbing text from panel

Posted on 2013-12-04
3
Medium Priority
?
261 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 14

Accepted Solution

by:
Dustin Hopkins earned 1400 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

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

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

I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Suggested Courses

618 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