ASP:前台添加PlaceHolder
<%@ Page Title="主页" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"
CodeBehind="Default.aspx.cs" Inherits="WebApplication1._Default" %>
<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
</asp:Content>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
<h2>
欢迎使用 ASP.NET!
</h2>
<p>
若要了解关于 ASP.NET 的详细信息,请访问 <a href="http://www.asp.net/cn" title="ASP.NET 网站">www.asp.net/cn</a>。
</p>
<p>
您还可以找到 <a href="http://go.microsoft.com/fwlink/?LinkID=152368"
title="MSDN ASP.NET 文档">MSDN 上有关 ASP.NET 的文档</a>。
</p>
<asp:PlaceHolder ID="PlaceHolder1" runat="server"><p></p></asp:PlaceHolder>
</asp:Content>
后台代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace WebApplication1
{
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
loopshowCourse();
}
protected void loopshowCourse()
{
Button mybutton = new Button();
mybutton.Text = "More";
mybutton.Click += new EventHandler(mybutton_Click);
PlaceHolder1.Controls.Add(mybutton);
}
protected void mybutton_Click(object sender, EventArgs e)
{
System.Web.UI.ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "tixin", "alert('该文件不存在或路径错误!')", true);
}
}
}
WindowsForms的代码
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsForms测试
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
Button mybutton = new Button();
mybutton.Text = "More";
mybutton.Click += new EventHandler(mybutton_Click);
mybutton.Parent = this;
}
protected void mybutton_Click(object sender, EventArgs e)
{
MessageBox.Show("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
}
}
Form 升起提示框 = new Form();
升起提示框.FormClosed += new FormClosedEventHandler(升起提示框_关闭);
void 升起提示框_关闭(object sender, EventArgs e)
{
MessageBox.Show("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
}