I have an asp.net page WineCompDefault.aspx which was initially implemented with VB code behind. I am now trying to change the code behind to CS. I modified the page directive in the aspx page as follows:
From -
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="WineCompDefault.aspx.vb" Inherits="WineCompDefault" %>
To -
<%@ Page Language="C#" AutoEventWireup="false" CodeFile="WineCompDefault.aspx.cs" Inherits="WineCompDefaultCS" %>
The WineCompDefault.aspx.vb file contained the following:
Imports Microsoft.VisualBasic
Imports System.Web.UI
Imports MarymonteDAL
Imports System.Data
Imports System.Data.OleDb
Partial Class WineCompDefault
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
End Sub
Protected Sub btnLogOn_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnLogOn.Click
Dim myLabel As Label
myLabel = Page.FindControl("lblTitle")
If Not myLabel Is Nothing Then
lblResults.Text = myLabel.Text
Else
lblResults.Text = "Could not find the label control."
End If
btnLogOn.Visible = False
End Sub
End Class
And the code converter from VB to C# gave the following (except I changed the class name to WineCompDefaultCS which I also changed in the page directive, so I could have both code behind files in the project)
using Microsoft.VisualBasic;
using System.Web.UI;
using System.Data;
using System.Data.OleDb;
partial class WineCompDefaultCS : System.Web.UI.Page
{
protected void Page_Load(object sender, System.EventArgs e)
{
}
protected void btnLogOn_Click(object sender, System.EventArgs e)
{
Label myLabel = default(Label);
myLabel = Page.FindControl("lblTitle");
if ((myLabel != null)) {
lblResults.Text = myLabel.Text;
} else {
lblResults.Text = "Could not find the label control.";
}
btnLogOn.Visible = false;
}
Public WineCompDefault()
{
Load += Page_Load;
}
}
The problem is it says "The type or namespace Public could not be found". I do not know what is wrong or missing. All help greatly appreciated.
(Also, note, I will remove the VB file once I am sure the CS is working correctly. That is why I would like to keep both in the project at this time)
You renamed the class but not the constructor. In C#, the constructor must match the class name.
WineCompDefault should be WineCompDefaultCS
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With