The name 'blMessages' does not exist in the current context

J

J055

Hi

I'm using VS2005. I get the above error when trying to build the solution.
Intellisense is OK.

// Code behind
protected void odsPublication_Inserted(object sender,
ObjectDataSourceStatusEventArgs e)
{
if (e.Exception == null)
{
blMessages.Visible = false;
}
}

//This is the webcontrol and ObjectDataSource

<asp:BulletedList ID="blMessages" runat="server" ForeColor="Red"
Visible="False">
</asp:BulletedList>
<asp:ObjectDataSource ID="odsPublication" runat="server"
InsertMethod="AddPublication"
OnInserted="odsPublication_Inserted">
<SelectParameters>
....

</SelectParameters>
<InsertParameters>
....
</InsertParameters>
</asp:ObjectDataSource>

Can you tell me what it really means and how to fix it?

Thanks
Andrew
 
M

Mike

J055 said:
Hi

I'm using VS2005. I get the above error when trying to build the solution.
Intellisense is OK.

// Code behind
protected void odsPublication_Inserted(object sender,
ObjectDataSourceStatusEventArgs e)
{
if (e.Exception == null)
{
blMessages.Visible = false;
}
}

//This is the webcontrol and ObjectDataSource

<asp:BulletedList ID="blMessages" runat="server" ForeColor="Red"
Visible="False">
</asp:BulletedList>
<asp:ObjectDataSource ID="odsPublication" runat="server"
InsertMethod="AddPublication"
OnInserted="odsPublication_Inserted">
<SelectParameters>
...

</SelectParameters>
<InsertParameters>
...
</InsertParameters>
</asp:ObjectDataSource>

Can you tell me what it really means and how to fix it?

This usually means that the control you are trying to reference is inside a
template field of a data control (gridview? repeater?) or otherwise not
directly accessible from wherever you have your code-behind. You need to
use the FindControl method to get to it:

BulletedList blist = (BulletedList)<DataControl>.FindControl("blMessages");

<DataControl> is the name of the housing control - GridView1 or whatever you
have called it.

HTH

Mike
 
S

Steven Cheng[MSFT]

Hi Andrew,

As for the ASP.NET web page, can you directly run it(view in the browser)
without compiling the entire website? I've found some other threads
discussing on this issue. It seems such behavior is likely due to the
status of that page in the project be corrupted. From those threads, you
can try the following things to see whether it works:

1. exclude the problem page from the project and close the VS IDE.
Reopen the solution/project and include the page again.

2. create a new page and copy all the markup and controls from the problem
page to the new page. remove the old problem page and compile the site
again.

Here is a thread on MSDN forum discussing on this:

http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=200532&SiteID=1

Hope this helps.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


This posting is provided "AS IS" with no warranties, and confers no rights.
 
M

Mike

Mike said:
This usually means that the control you are trying to reference is inside
a template field of a data control (gridview? repeater?) or otherwise not
directly accessible from wherever you have your code-behind. You need to
use the FindControl method to get to it:

BulletedList blist =
(BulletedList)<DataControl>.FindControl("blMessages");

<DataControl> is the name of the housing control - GridView1 or whatever
you have called it.

Oops. Missed the bit about Intellisense in your OP.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top