<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title>无标题页</title> </head> <body> <form id="form1" runat="server"> <asp:Button ID="Button1" runat="server" Height="30px" Text="Button" Width="69px" onclick="Button1_Click" /> <asp:TextBox ID="TextBox1" runat="server" ></asp:TextBox> <div> </div> </form> </body> </html>
using System.Web.UI; using System.Web.UI.HtmlControls; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Xml.Linq; public delegate void Y(); public partial class _Default : System.Web.UI.Page { public event Y X; protected void Page_Load(object sender, EventArgs e) { A a = new A(); X += a.f; } protected void Button1_Click(object sender, EventArgs e) { X(); } } public class A:_Default { public void f() { TextBox1.Text = "success"; } }
if the function Button1_Click(object sender, EventArgs e) is : protected void Button1_Click(object sender, EventArgs e) { TextBox1.Text="success"; } you said"you just create an instance of class _Default but the controls in it don't get instantiated" why it is right, when i click the button
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)