0

I am new to asp. I am using Visual Studio 2015 Community. I created a new Website over "File>New>Website>Website for AspWebForms "

Now my problem is I am writing now in CodeBehind, in my About.aspx.cs. If I try to get text from a asp Textbox over tb_bezeichnung.Text it says it's not in context.

So after long search I figured out that i need a Designer.cs, I cant recreate it or have any options to Convert to WebForm.

<%@ Page Title="About" Language="C#" MasterPageFile="~/MasterPage.Master"
         AutoEventWireup="true" CodeFile="About.aspx.cs" Inherits="About" %>

tb_bezeichnung is a Asp Textbox.

Project Explorer contents:

Picture of Project Explorer

About.aspx

About.aspx.cs

Leo.S
  • 21
  • 5
  • Please also include the definition of `myTexbox` as in your file `About.aspx` (click [edit] and then add it into the question). – Peter B Jan 25 '17 at 13:45
  • Check if the class name has the same name in the file of the inherit. – Federico Navarrete Jan 25 '17 at 13:59
  • I think its typo :) you have `TextChanged` event for a `TextBox` and there the `tb_bezeichnung` name is `tb_bezeichnung0` so changing this line will might solve your issue `string Test = tb_bezeichnung0.Text`. – Rahul Hendawe Jan 25 '17 at 14:12
  • please show `About.aspx` script and code behind – Saif Jan 25 '17 at 14:19
  • 1
    Note that based on the above you don't "need" a `designer` file - you have what's known as an Asp.Net _web site project_. Designer files are used in Asp.Net _web application project_ – EdSF Jan 25 '17 at 14:27
  • I think it was typo and that designer files was missing. I solved it by creating a new Project as "WebForm" and put all code inside it q.q i tried it before but i think the typo was all the fault. – Leo.S Jan 25 '17 at 14:29

2 Answers2

0

If I understand correctly, you want to take the value of your textbox, after let's say a button click for an example? Just create a Button and OnClick event and let's say add an Label in the design view, in the OnClick Method write:

in aspx file add:

<asp:Button ID="Button1" runat="server" Text="Click me !"  OnClick="Button1_Click" />    
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>

Code behind:

  protected void Button1_Click(object sender, EventArgs e)

    {
        Label1.Text = TextBox1.Text;           
    }
Toni
  • 57
  • 3
  • 15
0

Sounds like you've started with a "Web Site" instead of a "Web Application". A Web Site type uses older technology and is more difficult to maintain, I recommend starting over with a Web Application, which creates the designer files automatically. See Here..

ASP.NET Web Site or ASP.NET Web Application?

Community
  • 1
  • 1
Seano666
  • 2,238
  • 1
  • 15
  • 14