Reputation: 87
I am working on my first web site (using twitter oAuth) through Visual Studio 2012 for a class. I feel idiotic for having to ask this question as I'm sure it's extremely simple.
I am having trouble getting the codebehind to recognize any web elements on my .aspx page. I'm not sure if I need to change something in the options or if I am just missing something.
I have added a text box, via the toolbox, to "index.aspx" and gave it the id = 'txtUserName'. When I try to assign txtUserName.Text to a variable in the page_load, I get an error saying that 'txtUserName' does not exist in the current context.
Hopefully someone can make me smack my head and that I'm missing a simple tag or something.
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;
}
}
}
Upvotes: 4
Views: 7112
Reputation: 1
Delete the master page and add again the master (and copy existing contents excluding page directive), then the designer page also will get added and the issue will get resolved.
Upvotes: 0
Reputation: 51
What view are you using in VS2012? you could try flipping from code view to designer view to refresh your page.designer.cs. Also double check the designer.cs just to make sure your control really is there.
Upvotes: 1