Solved

grabbing text from panel

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

920 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

14 Experts available now in Live!

Get 1:1 Help Now