gpt4 book ai didi

asp.net - 后面的代码中无法识别 Web 控件

转载 作者:行者123 更新时间:2023-12-01 01:11:14 24 4
gpt4 key购买 nike

我正在通过 Visual Studio 2012 在我的第一个网站(使用 twitter oAuth)上工作。我觉得问这个问题很愚蠢,因为我确信它非常简单。

我无法让代码隐藏识别我的 .aspx 页面上的任何 Web 元素。我不确定是否需要更改选项中的某些内容,或者我是否只是遗漏了某些内容。

我通过工具箱向“index.aspx”添加了一个文本框,并为其指定了 id = 'txtUserName'。当我尝试将 txtUserName.Text 分配给 page_load 中的变量时,我收到一条错误消息,指出当前上下文中不存在“txtUserName”。

希望有人可以让我感到震惊,并且我错过了一个简单的标签或其他东西。

索引.aspx:

<%@ Page Language="C#" AutoEventWireup="True" CodeBehind="index.aspx.cs" Inherits="TwitterTest.index" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>TwitterTest!!!</title>
</head>
<body>
<form id="form1" runat="server">
<div>
Welcome to TwitterTest

</div>
<asp:TextBox ID="txtUserName" runat="server" Text=""></asp:TextBox>
</form>
</body>
</html>

index.aspx.cs:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Mvc;
using TweetSharp;

namespace TwitterTest
{
public partial class index : System.Web.UI.Page
{
static void Page_Load(object sender, EventArgs e)
{
string UserName = txtUserName.Text;
}

}
}

最佳答案

您的 Page_Load应该是 protected void Page_Load

关于asp.net - 后面的代码中无法识别 Web 控件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15423228/

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