Re: [問題] postback後 PlaceHolder裡的控制項消失
※ 引述《kisha024 (4545454554)》之銘言:
: 各位好
: 網頁一開始載入的時候 我讓PlaceHolder1裡面動態增加一個Button
: 但postback後 這個動態增加的Button會消失不見
: 我知道可以把 if (!IsPostBack) 拿掉 讓每次網頁載入時都動態增加一個Button
: 但我想請問 有辦法動態增加一次控制項後
: 該控制項就一直都存在 不會因為postback而消失嗎?
: 謝謝
: protected void Page_Load(object sender, EventArgs e)
: {
: if (!IsPostBack)
: {
: Button btn = new Button();
: btn.Text = "按鈕";
: PlaceHolder1.Controls.Add(btn);
: }
: }
寫在
Page OnPreInit..........event
記得override
protected override void OnPreInit(EventArgs e)
{
Button btn = new Button();
btn.Text = "test";
PlaceHolder1.Controls.Add(btn);
base.OnPreInit(e);
}
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 123.193.156.102
※ 文章網址: https://www.ptt.cc/bbs/C_Sharp/M.1477678524.A.6F6.html
※ 編輯: mepowerlmay (123.193.156.102), 10/29/2016 02:16:18
→
10/29 02:27, , 1F
10/29 02:27, 1F
推
10/29 09:20, , 2F
10/29 09:20, 2F
推
10/29 17:00, , 3F
10/29 17:00, 3F
→
10/29 17:01, , 4F
10/29 17:01, 4F
推
11/13 23:13, , 5F
11/13 23:13, 5F
討論串 (同標題文章)
本文引述了以下文章的的內容:
完整討論串 (本文為第 3 之 3 篇):