gpt4 book ai didi

.net - .aspx 页面后面代码的自定义命名空间

转载 作者:行者123 更新时间:2023-12-01 10:16:40 25 4
gpt4 key购买 nike

我正在使用 .NET2.0。假设有一个带有 txtInput 和 btnSomeAction 的简单 aspx 表单

   <asp:TextBox ID="txtInput" runat="server"></asp:TextBox>
<asp:Button ID="btnSomeAction" runat="server" CommandName="SomeAction" Text="Do"/>

然后在我拥有的表单背后的代码中

Protected Sub btnSomeAction_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSomeAction.Click
Dim s As String
s = txtInput.Text
End Sub

一切正常

然后我想将代码添加到自定义命名空间中

Namespace mycustomnamespace

这样做时我会得到一个编译器错误:

名称“txtInput”未声明 - 就好像代码不再连接到页面一样

我是否需要修改 aspx 页面以包含命名空间?部分类呢?

最佳答案

Do i need to modify the aspx page to include the namespace?, What about the partial class?

是的。在您的 aspx 文件的顶部,您应该看到类似

的内容
<%@ Page AutoEventWireup="false" Inherits="Blah.Foo.Bar" %>

其中 bar 是代码隐藏中类的名称,Blah.Foo 是它的命名空间。您需要将其更改为

<%@ Page AutoEventWireup="false" Inherits="mycustomnamespace.Bar" %>

关于.net - .aspx 页面后面代码的自定义命名空间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/298920/

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