Solved

grabbing text from panel

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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…

718 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