Solved

Cannot find control on my page

Posted on 2006-10-25
6
250 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
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.

 
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

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

Suggested Solutions

Title # Comments Views Activity
Replacing HTML tags in Textarea/Textbox 5 47
ASP.net VB.net Email  a webpage 3 31
Host asp.net pages 5 25
Run time Error 4 34
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…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

895 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

18 Experts available now in Live!

Get 1:1 Help Now