Identifier expected in C# - c#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace PageProcessingDemo
{
public partial class : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
}
}
i haven't done anything yet ,but it still showing " Identifier expected ",and pointing to ":" when double clicked.

You haven't specified class name.
Change your code to something like this:
public partial class MyPageClass : System.Web.UI.Page
P.S: Also, you have said that:
i haven't done anything yet
I am pretty sure that somebody has removed name of the class.
Additional details:
Try to add new WebForm to the project. Set the name of form to WebForm1.After clicking OK, VisualStudio will create three or two files depending on the type of the project:
WebForm1.aspx
WebForm1.aspx.cs
WebForm1.aspx.designer.cs (WebApplication project)
The *.aspx files are the markup and the *.aspx.cs files are the code-behind files. Code-behind files handle the .NET code for any server-side controls in the *.aspx files. And Asp.Net will generate your code behind files as partial classes like that:
public partial class WebForm1 : System.Web.UI.Page

Related

Cant recognize class in webform project

In my web form project I opened a folder called App_Code inside that folder I have class named Test123, but when I try to create instance inside WebForm1.aspx.cs it doesn't recognize that type
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace StephanProject_2.App_Code
{
public class Test123
{
}
}
My project structure:
I tried to add using StephanProject_2.App_Code;
What's the problem?
The class you are calling does not seem to be in the same namespace as the Webform1 class
if its from another namespace use.
StephanProject_2.App_Code.Test123 t = new StephanProject_2.App_Code.Test123()
Or alternatively in the top say
using StephanProject_2.App_Code;
When i try to same as your project then it works my code
You can see Here

Could not load type 'XXXX.aaa'

Hi,
I am having Could not load type error when I release my code into live environment. If I remove the code Inherits="CheckIEBrowser.Check" that gets rid of the error, it displays the page, but it doesn't work as it should.
Thanks in advance
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace CheckIEBrowser
{
public partial class Check : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!(IsPostBack))
{
...
Make a copy of Check.aspx and its CS fle to your local
Delete Check.aspx and Check.aspx.cs manually from directory
Clean Solution
Right click your solution add new form and name it as Check.aspx
Copy your local saved check.aspx contents to Check.aspx that we created newly (except line 1 )
do the same for check.aspx.cs also
rebuild your solution
Than try
if its not work, delete CheckIEBrowser.sln file and try

Can't find Database namespace in System.Data.Entity in ONE file

I have no idea. I just created a Global.asax and I'm just trying to use System.Data.Entity.Database and it has no idea what I want.
using System;
using HROpenEnrollment.Model;
using System.Data.Entity;
using HROpenEnrollment.Data.EntityFramework;
namespace HROpenEnrollment
{
public class Global : System.Web.HttpApplication
{
protected void Application_Start()
{
using System.Data.Entity.
}
The irritating part is I can use it elsewhere. Here's another file in the same project that works fine.
using System;
using HROpenEnrollment.Model;
using System.Data.Entity;
using HROpenEnrollment.Data.EntityFramework;
namespace HROpenEnrollment.Data.EntityFramework
{
public class Populate : DropCreateDatabaseIfModelChanges<OpenEnrollmentContext>
{
What gives? I get all the way to System.Data.Entity but it won't find anything after that.
Have you installed Entity Framework 5? Having only version 4 of the System.Data.Entity dll will net you nothing.

C# Inheritance Issues

Again, I'm fairly new at this sort of thing and perhaps the error message is telling me what it is and I'm simply not understanding, but... This code in anon.cs
namespace cheese.pies.org
{
using System;
using System.IO;
using System.Net;
using System.Web;
using System.Xml;
public class CasLogin : System.Web.UI.Page
{
private const string CasHost = "notimportant";
public static string GetId()
{
}
}
Ends up giving me an error when referenced here:
<% #Page Language="C#" Inherits="CasLogin" CodeFile="CasLogin.cs" %>
<script language="C#" runat="server">
protected void Page_Load(object sender, EventArgs e) {
String directoryId = CasLogin.GetId();
FormsAuthentication.RedirectFromLoginPage(directoryId, false);
}
</script>
The error is on line one and is:
Compiler Error Message: ASPNET: Make sure that the class defined in this code file matches the 'inherits' attribute, and that it extends the correct base class (e.g. Page or UserControl).
If I change it from
public class CasLogin : System.Web.UI.Page
to
public class CasLogin : Page
I get this error:
Compiler Error Message: CS0246: The type or namespace name 'Page' could not be found (are you missing a using directive or an assembly reference?)
If I change it from public class CasLogin : System.Web.UI.Page to
public class CasLogin : Page I get this error
You are missing the correct using statement for the Page class (System.Web.UI) thus when you remove the full qualification the compiler can no longer find the Page class.
You should also fully-qualify the class name in the Page directive, i.e. Inherits="cheese.pies.org.CasLogin"
Good
<% #Page Language="C#" Inherits="cheese.pies.org.CasLogin" CodeFile="CasLogin.cs" %>
Bad
<% #Page Language="C#" Inherits="CasLogin" CodeFile="CasLogin.cs" %>
Per your comment regarding a missing partial modifier:
public class CasLogin : System.Web.UI.Page
Should be:
public partial class CasLogin : System.Web.UI.Page
This tells the compiler that the CasLogin class is defined in multiple files (which is the case with web forms; the designer file is separate from the code behind file).
If it still doesn't work, I suggest recreating the page and copying any relevant code into it. Normally Visual Studio handles all of this automatically and this is a non-issue.
I'm pretty sure it should be
<% #Page Language="C#" Inherits="cheese.pies.org.CasLogin" CodeFile="CasLogin.cs" %>
For the other error you can use
using System.Web.UI;
public class CasLogin : Page
Without fully qualifying the class name it doesn't know which Page you're talking about, so you can be explicit when you declare the class or you can use a using statement. The first error is the same issue, it can't see the CasLogin class inside the chees.pies.org namespace
inherits needs to be:
Inherits="cheese.pies.org.CasLogin"
Looking at my own little test project/code, I see a few things noticably different: the "usings" come before the namespace declaration, and the use of partial class for code behind. Also, note that the Inherits has the fully qualified class (includes namespace).
in Default.aspx
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="WebApplication2._Default" %>
in Default.aspx.cs
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Diagnostics;
using System.Data;
namespace WebApplication2
{
public partial class _Default : System.Web.UI.Page
{

linking a new windows form with an existing project in c#

I have a c# problem. I have created a project called 'classproject' and I have added several forms to project successfully and successfully ran the program, but there is this other windows form that I just added and when I double-clicked on the form, it took me to the code view and brought out this:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class demo : Form
{
public demo()
{
InitializeComponent();
}
private void demo_Load(object sender, EventArgs e)
{
}
}
}
Now, my challenge is that the name of the project is meant to show by default after the namespace as in "namespace classproject" instead of "namespace WindowsFormsApplication1". Please can anyone help me out, what am I meant to do because have tried everything possible. Even if I change the name myself its still going to flag error... someone please help me as soon as possible.
I'm not sure exactly what your issue is. If you change the namespace manually in the code to classproject it should be fine. What error are you talking about? You would also need to change the designer code file as well (probably called demo.Designer.cs).
Just a side note as well. Standard naming convention for C# is to use Pascal-case (as in ClassProject).
You must change namespace in ALL files that was generated by Visual Studio. You can do it manually, or just set cursor on "WindowsFormsApplication1", press F2 and enter new name.
Optionaly you can also change namespace in project properties on Application tab - then all new files added to project will also have namespace that you set there.

Categories

Resources