加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

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

发布时间:2020-12-16 06:23:24 所属栏目:asp.Net 来源:网络整理
导读:我正在通过Visual Studio 2012为我的第一个网站(使用twitter oAuth)上课.因为不得不提出这个问题,我觉得很愚蠢,因为我确信它非常简单. 我无法让代码隐藏识别我的.aspx页面上的任何网页元素.我不确定我是否需要在选项中更改某些内容,或者我是否只是遗漏了某些
我正在通过Visual Studio 2012为我的第一个网站(使用twitter oAuth)上课.因为不得不提出这个问题,我觉得很愚蠢,因为我确信它非常简单.

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

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

希望有人可以让我咂嘴,我错过了一个简单的标签或其他东西.

的Index.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应该受到保护void Page_Load

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读