gpt4 book ai didi

c# - 将 Aspx 页面从 VB 转换为 CS

转载 作者:太空宇宙 更新时间:2023-11-03 14:10:02 25 4
gpt4 key购买 nike

我有一个 asp.net 页面 WineCompDefault.aspx,它最初是用 VB 代码实现的。我现在正在尝试将后面的代码更改为 CS。我修改了aspx页面中的page指令如下:

从 -

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="WineCompDefault.aspx.vb" Inherits="WineCompDefault" %>

至 -

<%@ Page Language="C#" AutoEventWireup="false" CodeFile="WineCompDefault.aspx.cs" Inherits="WineCompDefaultCS" %>

WineCompDefault.aspx.vb 文件包含以下内容:

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

从 VB 到 C# 的代码转换器给出了以下内容(除了我将类名更改为 WineCompDefaultCS,我还在页面指令中进行了更改,因此我可以在项目中同时拥有这两个代码隐藏文件)

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;
}
}

问题是它说“找不到公共(public)类型或命名空间”。我不知道有什么问题或遗漏了。非常感谢所有帮助。

(另外,请注意,一旦我确定 CS 正常工作,我将删除 VB 文件。这就是为什么我现在想将两者都保留在项目中)

最佳答案

您重命名了类而不是构造函数。在 C# 中,构造函数必须与类名匹配。

WineCompDefault 应该是 WineCompDefaultCS

关于c# - 将 Aspx 页面从 VB 转换为 CS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8099459/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com