|
Khan, not done yet? Let me give you an example, a total of four files, you copy to VS and compile:
my.ascx:
<% @ Control Language = "c #" AutoEventWireup = "false" Codebehind = "my.ascx.cs" Inherits = "test.my" TargetSchema = "http://schemas.microsoft.com/intellisense/ie5"%>
<asp: TextBox id = "TextBox1" runat = "server"> a4w </ asp: TextBox>
my.ascx.cs:
namespace test
{
using System;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
/// <summary>
/// My summary description.
/// </ summary>
public class my: System.Web.UI.UserControl
{
protected System.Web.UI.WebControls.TextBox TextBox1;
public string Retu1 {
get {
return this.TextBox1.Text;
}
set {
this.TextBox1.Text = value;
}
}
private void Page_Load (object sender, System.EventArgs e)
{
// Place user code here to initialize the page
}
#region Web Form Designer Generated Code
override protected void OnInit (EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Forms designer.
//
InitializeComponent ();
base.OnInit (e);
}
Ranch
/// <summary>
/// Designer supports required methods-don't use code editor
/// Modify the content of this method.
/// </ summary>
private void InitializeComponent ()
{
this.Load + = new System.EventHandler (this.Page_Load);
}
#endregion
}
}
webform1.aspx:
<% @ Page language = "c #" Codebehind = "WebForm1.aspx.cs" AutoEventWireup = "false" Inherits = "test.WebForm1"%>
<% @ Register TagName = "abc" TagPrefix = "my" src = "my.ascx"%>
<! DOCTYPE HTML PUBLIC "-// W3C // DTD HTML 4.0 Transitional // EN">
<HTML>
<HEAD>
<title> WebForm1 </ title>
<meta name = "GENERATOR" Content = "Microsoft Visual Studio .NET 7.1">
<meta name = "CODE_LANGUAGE" Content = "C #">
<meta name = "vs_defaultClientScript" content = "JavaScript">
<meta name = "vs_targetSchema" content = "http://schemas.microsoft.com/intellisense/ie5">
</ HEAD>
<body>
<form id = "Form1" method = "post" runat = "server">
<my: abc id = "myAscx" runat = "server" /> <FONT face = "宋体"> <BR>
</ FONT>
<asp: Button id = "Button1" runat = "server" Text = "Button"> </ asp: Button>
</ form>
</ body>
</ HTML>
webform1.aspx.cs:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using ICSharpCode.SharpZipLib.BZip2;
namespace test
{
/// <summary>
/// A summary description of WebForm1.
/// </ summary>
public class WebForm1: System.Web.UI.Page
{
protected System.Web.UI.WebControls.Button Button1;
protected test.my myAscx;
private void Page_Load (object sender, System.EventArgs e)
{
// read the value of the control below
Response.Write (myAscx.Retu1);
}
#region Web Form Designer Generated Code
override protected void OnInit (EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Forms designer.
//
InitializeComponent ();
base.OnInit (e);
}
Ranch
/// <summary>
/// Designer supports required methods-don't use code editor to modify
/// The contents of this method.
/// </ summary>
private void InitializeComponent ()
{
this.Button1.Click + = new System.EventHandler (this.Button1_Click);
this.Load + = new System.EventHandler (this.Page_Load);
}
#endregion
private void Button1_Click (object sender, System.EventArgs e)
{
// Set the value of the control below
myAscx.Retu1 = "ddd";
}
}
} |
|