THNG TIN: ASP.NET Code-?ng sau m?u t?ng quan

D?ch tiu ? D?ch tiu ?
ID c?a bi: 303247 - Xem s?n ph?m m bi ny p d?ng vo.
Bi vi?t ny ? c?p ?n Microsoft sau.NET Framework Class Khng gian tn th vi?n:
  • System.web.UI
Bung t?t c? | Thu g?n t?t c?

? Trang ny

TM T?T

Bi vi?t ny cung c?p m?t t?ng quan v? m? ?ng sau m h?nh, m ?c gi?i thi?u trong ASP.NET.

THNG TIN THM

ASP.NET h? tr? hai phng php tc gi? trang ? t?m:
  • Trong d?ng m?
  • M?-?ng sau

Trong d?ng m?

Trong d?ng m? l m? ?c nhng tr?c ti?p trong v?ng ASP.NET Trang. Cc m? sau y ?i di?n cho m?t m?u ASP.NET trang bao g?m trong d?ng m?:

Myinlinecode.aspx
<%@ Language=C# %>
<HTML>
   <script runat="server" language="C#">
   void MyButton_OnClick(Object sender, EventArgs e)
   {
      MyLabel.Text = MyTextbox.Text.ToString();
   }
   </script>
   <body>
      <form id="MyForm" runat="server">
         <asp:textbox id="MyTextbox" text="Hello World" runat="server"></asp:textbox>
         <asp:button id="MyButton" text="Echo Input" OnClick="MyButton_OnClick" runat="server"></asp:button>
         <asp:label id="MyLabel" runat="server"></asp:label>
      </form>
   </body>
</HTML>
				

M?-?ng sau

M?-?ng sau ? c?p ?n m? cho ASP c?a b?n.NET trang ?c ch?a trong m?t t?p tin l?p h?c ring bi?t. i?u ny cho php m?t lm s?ch ly thn c?a b?n HTML t? logic tr?nh by c?a b?n. Sau y m?u minh ho? m?t ASP.NET m?-?ng sau trang:

MyCodebehind.aspx
<%@ Language="C#" Inherits="MyStuff.MyClass" %>
<HTML>
    <body>
        <form id="MyForm" runat="server">
        <asp:textbox id="MyTextBox" text="Hello World" runat="server"></asp:textbox>
        <asp:button id="MyButton" text="Echo Input" Onclick="MyButton_Click" runat="server"></asp:button>
        <asp:label id="MyLabel" runat="server" />
        </form>
    </body>
</HTML>
				
Mycodebehind.CS
using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace MyStuff
{
    public class MyClass : Page
    {
        protected System.Web.UI.WebControls.Label MyLabel;
        protected System.Web.UI.WebControls.Button MyButton;
        protected System.Web.UI.WebControls.TextBox MyTextBox;

        public void MyButton_Click(Object sender, EventArgs e)
        {
            MyLabel.Text = MyTextBox.Text.ToString();
        }
    }
}
				
Trong m?u tr?c, b?n c th? s? d?ng c php sau y ? bin d?ch Mycodebehind.CS:
CSC.exe /out:mycodebehind.dll /t:library mycodebehind.cs
Khi b?n s? d?ng m? sau y, m?-?ng sau trang th?a h?ng t? cc Trang l?p h?c. Cc Trang l?p h?c n?m trong cc System.web.UI khng gian tn:
public class MyClass : Page
				
K? th?a t? cc Trang l?p cho php truy c?p trang m?-?ng sau ASP.NET n?i t?i cc ?i t?ng, ch?ng h?n nh Yu c?u v Ph?n ?ng. Ngoi ra, k? th?a t? cc Trang l?p cung c?p m?t khun kh? ? x? l? s? ki?n cho cc i?u khi?n trong v?ng ASP.NET trang.

Trong m?u tr?c, m?-?ng sau trang ?c bin so?n tr?c khi ASP.NET ch?y. Ngoi ra, b?n c th? tham kh?o l?p m?-?ng sau b?ng cch s? d?ng SRC m?t t? kha nh sau:
<%@ Language="C#" Inherits="MyStuff.MyClass" src="MyCodebehind.cs" %>
				
Trong tr?ng h?p ny, ASP.NET bin d?ch m?-?ng sau trang trn bay. Thng bo r?ng b?c ny bin d?ch ch? x?y ra khi cc t?p tin m? pha sau ?c C?p Nh?t ( pht hi?n thng qua m?t s? thay ?i d?u th?i gian).

M?-?ng sau h? tr? trong Visual Studio.NET

Khi b?n s? d?ng Microsoft Visual Studio.NET ? t?o ASP.NET Web Forms, M?-?ng sau trang l phng php m?c ?nh. Ngoi ra, Visual Studio.NET t? ?ng th?c hi?n precompilation cho b?n khi b?n xy d?ng gi?i php c?a b?n. Lu ? r?ng m?-?ng sau cc trang ?c t?o ra trong Visual Studio.NET bao g?m m?t ?c bi?t trang thu?c tnh, CodeBehind, m Visual Studio.S? d?ng NET.

THAM KH?O

Cho thng tin b? sung % 1, nh?p vo s? bi vi?t % 2 d?i y ? xem cc i?u % 2 trong c s? ki?n th?c Microsoft:
313105 L?I: Khng th? bin d?ch m?-?ng sau t?p tin s? d?ng thu?c tnh Src trn m?t chia s? UNC

Thu?c tnh

ID c?a bi: 303247 - L?n xem xt sau cng: 26 Thang Tam 2011 - Xem xt l?i: 2.0
p d?ng
  • Microsoft ASP.NET 1.1
  • Microsoft ASP.NET 1.0
T? kha:
kbinfo kbwebforms kbmt KB303247 KbMtvi
My d?ch
QUAN TRONG: Bi vi?t ny ?c d?ch b?ng ph?n m?m d?ch my c?a Microsoft ch? khng ph?i do con ng?i d?ch. Microsoft cung c?p cc bi vi?t do con ng?i d?ch v c? cc bi vi?t do my d?ch ? b?n c th? truy c?p vo t?t c? cc bi vi?t trong C s? Ki?n th?c c?a chng ti b?ng ngn ng? c?a b?n. Tuy nhin, bi vi?t do my d?ch khng ph?i lc no c?ng hon h?o. Lo?i bi vi?t ny c th? ch?a cc sai st v? t? v?ng, c php ho?c ng? php, gi?ng nh m?t ng?i n?c ngoi c th? m?c sai st khi ni ngn ng? c?a b?n. Microsoft khng ch?u trch nhi?m v? b?t k? s? thi?u chnh xc, sai st ho?c thi?t h?i no do vi?c d?ch sai n?i dung ho?c do ho?t ?ng s? d?ng c?a khch hng gy ra. Microsoft c?ng th?ng xuyn c?p nh?t ph?n m?m d?ch my ny.
Nh?p chu?t vo y ? xem b?n ti?ng Anh c?a bi vi?t ny:303247

Cung cp Phan hi

 

Contact us for more help

Contact us for more help
Connect with Answer Desk for expert help.
Get more support from smallbusiness.support.microsoft.com