Solved

Cannot find control on my page

Posted on 2006-10-25
6
253 Views
Last Modified: 2008-01-09
OK, I added the following in my aspx page:

...
<p runat="server" id="paragraph1">some text is here....</p>
...

My codebehind (.cs) has this trying to reference this tag.  Wehave thi working on other projects like this, same code.  But for some reason I get "C:\directorywhatever\mypage.aspx.cs(68): The type or namespace name 'paragraph1' could not be found (are you missing a using directive or an assembly reference?)"  

There is definitely no missing .dll, this is simply referencing an html server-side control now that I put runat="server" id="paragraph1" in that tag

I'm using VS 2003 to build, what could it be?  Why isn't it finding that server tag?

I have othe rpages in thi sproject, aspx pages that are setup like this, and after adding that paragraph tag in, the code-behind for those other pages can see it fine.  It's just on 2 of the pages that cannot find it like this, wondering if I need to add a reference somwhere to make VS 2003 aware of the control?
0
Comment
Question by:dba123
6 Comments
 
LVL 9

Expert Comment

by:HappyFunBall
ID: 17807102
In the code behind file you'll need to add a reference to that new control.  Other controls are referenced at the top of the code behind, usually automatically when you use VS2003 designer to add them to your page.  If you edit the HTML directly, you just need to add the control declaration yourself.

I don't know the C# equivalent off the top of my head, but in VB it looks like this:

"Protected WithEvents paragraph1 as LiteralControl"
0
 
LVL 9

Expert Comment

by:HappyFunBall
ID: 17807110
I said reference a few times in that response, but I mean declaration...
0
 
LVL 6

Accepted Solution

by:
Roopesh_7 earned 500 total points
ID: 17807449
hey add this

protected System.Web.UI.HtmlControls.HtmlGenericControl paragraph1;

to your code behind page...else build your project once more...
0
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
LVL 15

Expert Comment

by:Solar_Flare
ID: 17809098
have you switched to design view rather than html since you added it? I have found that VS Express editions are not aware of new controls until I have switched to design view. Probably not relavent but thought I would mention it just in case as a possibility...
0
 
LVL 6

Expert Comment

by:Roopesh_7
ID: 17812480
yes thats right...if u r swiched to disgn view it is automatically created.... some controls arenot created.. for that we manually add that....
0
 
LVL 2

Expert Comment

by:apgourlay
ID: 17813456
The only thing to watch out for in VS2003 is when you switch to Design view it can really mess up your HTML. I'd manually add the reference to code behind page.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

829 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