I'm currently working on a project I've just received that is asp.net + vb.
I have to add a gridview in one part of the page, but it simply won't let me set the datasource
<%# Page Language="VB" MasterPageFile="~/Common/Common.master" title=whatever" %>
<%# Register TagPrefix="uct" TagName="SubmenuControl" Src="whatever.ascx" %>
this loads the masterpage and a simple menu.
I had to create a page, so I've based myself on the existing ones:
somepage.asp
Based on othes pages, I've copied the code behind insertion method:
<%# Import Namespace="somelibrary" %>
<%# Import Namespace="otherlibrary" %>
<script runat="server">
'some vb code
</script>
But when I compile, I get the message:
alt text http://dl.dropbox.com/u/3045472/ex.png
Did I forget something? I use simple system references (IO and DATA) it should work without any adition, I've added anyway the .data reference, but it doesn't work, so, what should I do ?
Since there's no vb coding in this question, you could answer it in C# or VB if any addition is needed in the code behind.
info:
0-Visual Studio 2008
1-Works without this page
2-VB.NET but you can use C#
3-I'm new to asp, don't freak out
4-Without the references, the objects that use those references aren't recognized (underlined as reference missing) so the references load OK in theory.
5-If instead of adding the reference in the beginning I give the complete path to the object (ex.: system.io.fileinfo) I get the exact same error.
6-I'm watching this question, anything else you need to know, comment.
You aren't compiling, you're running in debug mode. The startup project you have set is not the ASP.NET project. In Solution Explorer, right click on the web project itself, and select "Set as startup project". Or to simply compile, try Ctrl-Shift-B.
Visual Studio often "runs" whichever project you have open in the text editor (depending on how you invoke the run/build command).
Try opening the default.aspx page in the text editor before you run/debug the project.
Related
I have the following HTML in an .aspx:
<div ID="divText" runat="server" style="position:absolute;top:60px; left:800px; width:600px; height:100px; z-index:2;font-size:200%">
</div>
Then in the code behind, IntelliSense finds the 'divText' but I get the compile error listed in the title
string productEdition = ConfigurationManager.AppSettings["Club"];
divText.InnerHtml = productEdition;
The compile error:
Error 3 The name 'divText' does not exist in the current context
The thing is the same EXACT html and code work in another file. We have tried everything. Any ideas?
In case other suggestions don't work, delete designer file, right click the markup file and click "convert to web application".
This error usually occours when you have copy pasted an aspx file. Please verify that your aspx is pointing to the correct cs file. Also check the names of the two files.
Other option is that there is something wrong with your designer file. If you want to Visual studio to regenerate your designer.cs file, you can go into design mode, make a small change and save the file.
Let me know if none of this works (90% of the time this issue is caused by this).
I had a similar issue when getting old VS2005 aspx/aspx.cs files into a new project in VS2013. I resolved this by creating a new web application, creating a new webform for each aspx page and copying the code for .aspx and .cs. Once copied I have to change the .cs files first line to use CodeBehind instead of CodeFile .
<%# Page Language="C#" AutoEventWireup="true" CodeFile="Login.aspx.cs" Inherits="_Login" %>
TO
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="Login.aspx.cs" Inherits="_Login" %>
I hope this helps someone else.
Most likely the control variable did not get added to the aspx.designer.cs file. You can re-add the control and Visual studio might add it for you or you can add it manually to the designer.
protected global::System.Web.UI.HtmlControls.HtmlGenericControl divText;
Right-click on the ASPX (or ascx) file, and select Convert to web application (or something like that). That will force a refresh on the designer file.
and you can right-click on project in solution explorer and select to web application. in this case all of your project files will be change.
if you can't see convert to web application after right click, you can click on project menu and you see convert to web application in bottom
I think the problem mix of 3 issue in the middle:
check if namespace in the code MyFile.aspx.cs file is the same of project.
in the MyFile.design.aspx.cs the namespace should match with previous file
if the design file of your aspx page in the partial class have declared the control that give that error.
In my case the issue appeared after copy/added the existing aspx file.
After checked if all namespace are correct the issue was solved.
Looks like your problem may be the uppercase ID which is not setting the id of your element. Also not sure how the id becomes an object given the code you posted.
I have an ASPX page with no code behind (that is, no .aspx.cs with the same name). In the code is this line:
<div style="overflow: hidden; text-align: center; z-index: 105;">
<%= MainNavBarHTML %><%= SubNavBarHTML %>
</div>
I've searched the rest of the program for MainNavBarHTML and SubNavBarHTMl, but can't find any reference to them. How do I find what fills those elements?
You might want to check out the CodeFile vs CodeBehind question.
If your ASPX markup has the CodeFile directive, it will look for the associated .cs file:
<%# Page
Language="C#"
CodeFile="CustomerDetail.aspx.cs"
Inherits="SomePage" %>
If, instead, it has the CodeBehind directive listed it will look in the Bin folder for an assembly that has the class defined:
<%# Page
Language="C#"
CodeBehind="CustomerDetail.aspx.cs"
Inherits="SomePage" %>
The naming of these two directives is beyond unfortunate. If the application is using CodeBehind (which it sounds like it is) you may not have access to the source and will be unable to view the definition for those properties, short of using a .NET reflection tool against the compiled assemblies.
In Visual Studio, Put your cursor on the text and press F12 to jump to definition or right-click on the text and choose "Go to definition".
Adding this as an answer now (rather than in the comments).
Your project will have the code somewhere, though it may be part of another library (DLL).
If you right-click on the property (in this case either MainNavBarHTML or SubNavBarHTML, and from the context-menu select "Go to definition" VS will show you either the code (if it's in a *.cs page) or load the object browser and navigate to that property, allowing you to see exactly where the property is located.
Depending on your VS settings F12 may do nothing - does nothing on mine for example. Right-clicking and choosing "Go to definition" is the most stable way to navigate - in my opinion.
Boiler, the code is still there, you just have to select the file and hit F7 and you will see the code...
Hi I am supposed to design a complete website and use .net for doing so. I used dreamweaver to design/create all the web pages. Now I am trying to load them to visual studio by just changing the extension from .html to .aspx to create c# code for those pages. These are problems I am having:
Double clicking on buttons/textboxes is not opening the .cs page. Infact I am not having any .cs page created for these pages.
what changes should I make to make this happen?
You can add <%# Page Language="C#" CodeFile="page_name.aspx.cs" %> and create cs file names page_name.aspx.cs and page class in it, but there is a easier way to do that.
Just create new aspx file in Visual Studio, and replace its content with your html content. Don't remove top line of aspx file.
Note: You should create aspx files in Visual Studio anyway. Probably you will have to change your button, input, or any other form controls to aspx controls. So there is a lots of work to do.
I have a QuestionControl.ascx and a QuestionControl.ascx.cs code behind file I copied to a new project. When I build the project any references in the code behind file to controls declared in the ascx gives me this error:
'QuestionControl' does not contain a
definition for 'rdbtnlstQuestion1' and
no extension method
'rdbtnlstQuestion1' accepting a first
argument of type 'QuestionControl'
could be found (are you missing a
using directive or an assembly
reference?)
This is at the top of my *.ascx:
<%# Control Language="C#" AutoEventWireup="true" CodeFile="QuestionControl.ascx.cs" Inherits="QuestionControl" %>
I've also tried CodeBehind:
<%# Control Language="C#" AutoEventWireup="true" CodeBehind="QuestionControl.ascx.cs" Inherits="QuestionControl" %>
This is the top of my class in the codebehind file, it is not contained in a namespace:
public partial class QuestionControl : System.Web.UI.UserControl
{
Try deleting your designer file. VS.NET should recreate it for you when you open the ascx file. I've had problems like this in the past where the designer gets out-of-sync for some reason, and deleting it usually fixes the problem.
Another solution is to:
open your .ascx page in design view
right click anywhere on the page and select Refresh
(.ascx.designer.cs file may need to to be closed while doing refresh for this to work)
In VS2017 there is no option 'Convert to Web Application' in the context menu of the .ascx file. Instead you need to select to .ascx file then click on 'Project' in the upper menu and select 'Convert to Web Application' (which is all the way down in the Project menu.
What worked form me was listed on another SO answer and I can't find it so I'm repeating it here.
Try deleting your "ReflectedSchemas" folder in
C:\Users\YOURUSENAME\AppData\Roaming\Microsoft\VisualStudio\15.0_079f391b\ReflectedSchemas
This worked for me. Sometimes I get the "unrecognized" errors, and I delete this folder again. Many thanks to the OP. Been driving me crazy for years. Now I have no "squiggles" in the HTML and no "red bars" in the code behind (aspx.cs)
I had problems for example creating a dropdownlist inside a gridview. What I did is creating the ddl outside of the gv until the desinger.cs recognized it and afterwards moved the control inside the gv... hope this helps
I was having the same issue, the code-behind didn't recognize the controls on the .aspx page. I'm using VS 2012. I right-clicked the project; clicked on Convert to Web Application; and it added all the designer files that weren't there at all before. I rebuilt everything and it's good now.
Ok, so, my visual studio is broken. I say this NOT prematurely, as it was my first response to see where I had messed up in my code. When I add controls to the page I can't reference all of them in the code behind. Some of them I can, it seems that the first few I put on a page work, then it just stops.
I first thought it may be the type of control as initially I was trying to reference a repeater inside an update panel. I know I am correctly referencing the code behind in my aspx page. But just in case it was a screw up on my part I started to recreate the page from scratch and this time got a few more controls down before VS stopped recognizing my controls.
After creating my page twice and getting stuck I thought maybe it was still the type of controls. I created a new page and just threw some labels on it. No dice, build fails when referencing the control from the code behind.
In a possibly unrelated note when I switch to the dreaded "design" mode of the aspx pages VS 2008 errors out and restarts.
I have already put a trouble ticket in to Microsoft. I uninstalled all add-ins, I reinstalled visual studio.
Anyone that wants to see my code just ask, but I am using the straight WYSIWYG visual studio "new aspx page" nothing fancy.
I doubt anyone has run into this, but have you?
Has anyone had success trouble shooting these things with Microsoft? Any way to expedite this ticket without paying??? I have been talking to a rep from Microsoft for days with no luck yet and I am dead in the water.
Jon Limjap: I edited the title to both make it clear and descriptive and make sure that nobody sees it as offensive. "Foo-barred" doesn't exactly constitute a proper question title, although your question is clearly a valid one.
The above fix (deleting the temp files) did not work for me. I had to delete the PageName.aspx.designer.cs file, then right-click my page, and choose "Convert to Web Application" from the context menu.
When Visual Studio attempted to rebuild the designer file, it encountered (and revealed to me) the source of the problem. In my case, VS had lost a reference to a DLL needed by one of the controls on my page, so I had to clean out the generated bin folders in my project.
try clearing your local VS cache. find your project and delete the folder. the folder is created by VS for what reason I honestly don't understand. but I've had several occasions where clearing it and doing a re-build fixes things... hope this is all that you need as well.
here
%Temp%\VWDWebCache
and possibly here
%LocalAppData%\Microsoft\WebsiteCache
Is the control that you are trying to reference inside of the repeater?
If so then you need to look them up using the FindControl method.
For example for:
<asp:Repeater ID="Repeater1" runat="server">
<ItemTemplate>
<asp:LinkButton ID="LinkButton1" runat="server">stest</asp:LinkButton>
</ItemTemplate>
</asp:Repeater>
You would need to do this to reference it:
LinkButton lb = Repeater1.FindControl("LinkButton1");
In my case, I was working with some old web site code, which I converted to a VS2008 solution. I encountered this same problem.
For me, the fix was to right-click the Web Sites project in the Solution Explorer and select Convert to Web Application. This created designer.cs files for all pages, which did not yet have these files before.
you will also find .net temp files which are safe to delete here:
C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files
I observed this happens because of missing .designer.cs file. Following fixed this issue in my case (basically I had these files copied from VS 2005 web project to VS 2010 project): Right Click on .aspx file and select menu "Convert to Web site", this will create .designer.cs file and then it should work file.
In my case new asp controls I added to an existing were not being detected.
What worked for me was forcing a recompile by renaming an existing control to break the build eg: changing <asp:TextBox ID="txtTitle" runat="server" /> to <asp:TextBox ID="txtTitle2" runat="server" />
When I corrected the ID and rebuilt a new designer file was generated with the corrected ID and new controls.
right click on project name and select "Clean". then, check your bin folder if it has any dll remaining. if so, delete it. that´s it. just rebuild and every thing will work fine.
This can also happen if the Inherits property on the source page doesn't match the class name in the code behind. Generally speaking, this would probably only happen if you copy/pasted a .ascx/.aspx file and forgot to update it.
Example:
<%# Control AutoEventWireup="false" CodeBehind="myControl.ascx.vb" Inherits="myProject.myWrongControl" %>
The the code behind class:
Partial Public Class myControl
we cannot change the code when the application is running .To do so first click on the stop button on the top which will halt your application .now click on the button in design mode ,it will insert the code in .aspx.cs file ,then write the code in it
Check out your aspx file on errors, once I've faced with that problem
I had this happen a few times and it happened again today for a new reason. I normally run my project through IIS but needed to run it locally to debug. I normally run on port 80 in IIS and 81 in debug, but I had some settings in the web.config that used 80 so I just killed the site in IIS and switched the website to port 80 in the project settings. For whatever reason, this messed everything up and created the problem described in the OP. I started trying things one by one, including all the advice mentioned here, but switching the port back to 81 in the project settings is what ended up working.
For me, deleting/renaming the files in the following location worked:
C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\myvirtualwebsite\e331e0a9
Just to add my two cents with this problem.
The only thing from all the above that worked for me was the "Clean" and then delete anything left in the bin folder. Rebuild and all controls started working then.
FYI...I was having this problem too and I ended up fixing it by deleting the existing .designer.vb file, right-clicking on the project and choosing Convert to Web Application. It then showed the real "error" that was causing the GUI to crap itself. Turned out I had used the same name for 2 other labels but that wasn't being shown in the error list window. Once I renamed one of the 2 other labels it built fine and stopped giving me trouble.
You have to add
runat="server"
to each element in your page.