I'm a PHP developer learning ASP.NET, and it seems one has to twist an arm just to do something simple like connect to a database.
When I do the following.
<%# Page Language="C#"%>
<%
using System.Data.SqlClient;
using MySql.Data.MySqlClient;
//Connect to database
SqlConnection connection = new SqlConnection("Server=MYSQL5003.Smarterasp.net;Database=yyy;Uid=zzz;Pwd=xxx;");
//Determine the action we're performing
switch(Request.QueryString["action"]){
case "unsubscribe":
Response.Write(Request.QueryString["email"]);
break;
case "export":
Response.Write(Request.QueryString["action"]);
break;
default:
//Default action
break;
}
%>
I get a syntax error for some reason.
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.
Compiler Error Message: CS1003: Syntax error, '(' expected
Source Error:
Compilation Error
Line 1: <%# Page Language="C#"%>
Line 2: <%
Line 3: using System.Data.SqlClient;
Line 4: using MySql.Data.MySqlClient;
Line 5: //Connect to database
Am I not supposed place the "using" statements in another file?
You have to use #Import when bringing in a namespace inline on an aspx page.
<%# Import Namespace="System.Data.SqlClient" %>
Related
I want to Deploy my ASP.Net Web Application on another Server IIS.
I already deploy it on Server but when I run that application that gives an error:
Description: An error occurred during the parsing of a resource required to service this request. Please review the following specific parse error details and modify your source file appropriately.
Parser Error Message: Could not load type 'PhurtiCRM.AutoScript'.
Source Error:
Line 1: <%# Page Language="C#" AutoEventWireup="true" CodeBehind="AutoScript.aspx.cs" Inherits="PhurtiCRM.AutoScript" %>
Line 2:
Line 3: <!DOCTYPE html>
My C# Code :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using AutoScript.BO;
using AutoScript.BLL;
namespace PhurtiCRM
{
public partial class AutoScript : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
}
}
This question already has answers here:
Parser Error Message: Could not create type 'xxx'
(3 answers)
Closed 8 years ago.
i am new to .net and i have to create a webservice for connecting with android.i got a simple example code and i put it in a mew webservice application and run it in debug mode.but it shows the following error in firefox.pls help to correct it.
Service1.asmx.cs
using System;
using System.Collections.Generic;
using System.Web;
using System.Web.Services;
namespace HelloAndroid
{
[WebService(Namespace = "http://sample.com/")]
public class Service1 : System.Web.Services.WebService
{
[WebMethod]
public string SayHello()
{
return "Hello, Android from .NET";
}
}
}
error
Server Error in '/' Application.
Parser Error
Description: An error occurred during the parsing of a resource required to service this request. Please review the following specific parse error details and modify your source file appropriately.
Parser Error Message: Could not create type 'WebService1.Service1'.
Source Error:
Line 1: <%# WebService Language="C#" CodeBehind="Service1.asmx.cs" Class="WebService1.Service1" %>
Source File: /Service1.asmx Line: 1
Version Information: Microsoft .NET Framework Version:2.0.50727.6387; ASP.NET Version:2.0.50727.6387
You've probably changed the namespace from WebService1 to HelloAndroid in Service1.asmx.cs. You need to update Service1.asmx file as well.
I am running asp.net, C#4.0 application in VS2010. I get the following compilation error:
Server Error in '/' Application.
Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.
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).
Source Error:
Line 1: using System;
Line 2: using System.Collections.Generic;
Line 3: using System.Linq;
My page attribute is :
<%# Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs"
EnableEventValidation="false" Inherits="jsPlumb_jsPlumb_Default2" %>
my c#codebehind class:
namespace CompanyDisplay.jsPlumb.jsPlumb.jsPlumb
{
public class jsPlumb_jsPlumb_Default2 : System.Web.UI.Page
{
}
}
i want namespace to present for running some webservice applications.
Try to do this :
add batch=”false” in the compilation tag of your applications web.config file as shown below
compilation debug=”true” batch=”false”
clean solution
delete the temporary files folder in Visual Studio(the folder which it shows in the exception)
do an iisreset and the rebuild my code again
I got the ANSWER ; I should give the inherit attribute as;
inherits="CompanyDisplay.jsPlumb.jsPlumb.jsPlumb.jsPlumb_jsPlumb_Default2"
This error shows up when code-behind class name doesn't match "inherits" attribute on your aspx page. Maybe you tried to rename something?
Furthermore, I've seen this error, when you try to view a new page, but didn't compile the source, so even though your aspx exists, it can't fight the corresponding code-behind class.
Edit:
You have a completely messed up naming conventions, no surprise you're having troubles to match class names properly.
Sorry, but this is just preposterous!
inherits="CompanyDisplay.jsPlumb.jsPlumb.jsPlumb.jsPlumb_jsPlumb_Default2"
Fix your conventions and maybe you find yourself having source files like this:
CodeBehind="Default.aspx.cs" Inherits="MyNamespace.jsPlumb.Default"
Don't do it like jsPlumb.jsPlumb.jsPlumb....That's just a nightmare!
How do I fix this error?
I'm running .NET Framework v4.0.30319 so the Framework shouldn't be an issue. I'm not using any DLL files or bin directories. How do I setup the IIS/Virtual Directory if I'm using Forms Authentication for the whole website using VS2010?
Description: An error occurred during the parsing of a resource required to service this request. Please review the following specific parse error details and modify your source file appropriately.
Parser Error Message: Could not load type
'ACAWebApplication.Pages.State_Carrier_Search'.
Source Error:
Line 1: <%# Page Title="ACA Web App - State Carrier Search" Language="C#"
MasterPageFile="~/Pages/User.Master" AutoEventWireup="true"
CodeBehind="State_Carrier_Search.aspx.cs"
Inherits="ACAWebApplication.Pages.State_Carrier_Search" %>
Line 2: <asp:Content ID="Content1" ContentPlaceHolderID="HeadContent"
runat="server">
Line 3: <style type="text/css">
Source File: /Pages/State_Carrier_Search.aspx Line: 1
The Codebehind for State_Carrier_Search.aspx.cs file:
namespace ACAWebApplication.Pages
{
public partial class State_Carrier_Search : System.Web.UI.Page
{
protected void Page_LoadS(object sender, EventArgs e)
The code for State_Carrier_Search.aspx file is as follows:
<%# Page Title="ACA Web App - State Carrier Search" Language="C#" MasterPageFile="~/Pages/User.Master" AutoEventWireup="true" CodeBehind="State_Carrier_Search.aspx.cs" Inherits="ACAWebApplication.Pages.State_Carrier_Search" %>
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
thanks!
Thou shalt not name class and namespace the same
THIS is Your problem
namespace ACAWebApplication.Pages
{
public partial class ACAWebApplication.Pages.State_Carrier_Search : System.Web.UI.Page
{
The parser sees an ACAWebApplication.PAges namespace and sees ACAWebApplication.Pages class name. This is probably legal but it is very wrong
Drop the ACAWebApplication.PAges from the class name and it should work. Was it autogenerated or You have extracted the namespace from the class name. Either way change it
and read
Eric lippert musings on it - whole series quite enlightening
Is the .NET version correctly set in IIS? This could be a .NET 2.0 app trying to run on the 1.0 framework.
Please refer to the Specify a .NET Framework Version for an Application Pool (IIS 7) article to learn more how to specify a .NET Framework version for an application pool.
<%# Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
But I am getting this error... tried making them match and everything, what is it suppose to be?
Server Error in '/' Application.
Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.
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).
Source Error:
Line 14: namespace FlashCards
Line 15: {
Line 16: public partial class _Default : System.Web.UI.Page
Line 17: {
Line 18: protected int indexKey = 0;
Source File: c:\Users\Ryan\documents\visual studio 2008\websites\flashcards\Default.aspx.cs Line: 16
Inherits requires the full name of the class so you need to include the namespace as well. Try replacing the
Inherits="_Default"
with
Inherits="FlashCards._Default"