看板C_Sharp
标 题Re: 求助PlaceHoder的用法?
发信站元智大学风之塔 (Wed Nov 3 19:38:07 2004)
转信站ptt!ctu-reader!ctu-peer!news.nctu!nctumenews!news.ind.ntou!news.ntu!ne
※ 引述《[email protected] (tomex_ou)》之铭言:
> ※ 引述《[email protected] (怎麽来,怎麽走..是吧?)》之铭言:
> : u wanna this?
> : private void Page_Load(Object sender, EventArgs e)
> : {
> : System.Web.UI.WebControls.Button button1 = new Button();
> : button1.Text = "koji";
> : PlaceHolder1.Controls.Add(button1);
> : button1.Click += new EventHandler(button1_Click);
> : }
> : void button1_Click(object sender, EventArgs e)
> : {
> : Label1.Text = "Good Clicked!!";
> : }
> 动态control的重点在於它的事件及传入的参数
> 不可能事先定义好对应的envent函式,除非大家都共用同一个,
> 假如成立,这参数 (object sender, EventArgs e)将会很有趣!
> 谢谢,我有想到一点idea了,
> 等我试出再分享给大家...
你是希望"动态"加入元件,而非page_Load是吧?
如果这样做,就是事件处理会无法被触发,你是说像这样的事情吗?
如果是的话,简单说就是必须在事件处理之前要设定好所有相关动作
对於page来说,找不到元件也就没办法处理事件
把产生的元件丢到Session.
然後Page_Load时从Session读出来并给他相对应处理函式!!
这样就可以动态放元件,然後事件又可以运作!!
--
※ Origin: 元智大学 风之塔 <bbs.yzu.edu.tw>
※ From : c05105b.gdorm.yzu.edu.tw
※ X-Info: Re: 求助PlaceHoder的用法?
※ X-Sign: 10OHGOV9sm5VM4vI.Gto (04/11/03 19:38:07 )