作者hirabbitt (兔子)
看板Web_Design
標題[問題] ASP.NET postback後抓不到Control
時間Thu Feb 9 18:21:19 2017
public DropDownList ddl;
protected void Page_LoadComplete(object sender, EventArgs e)
{
ddl = new DropDownList();
ddl.ID = "ID";
node.Controls.Add(ddl); // node is a TableCell
}
//<asp:TextBox
// AutoPostBack="true" OnTextChanged="OnTextChanged" runat="server">
//</asp:TextBox>
protected void OnTextChanged(object sender, EventArgs e)
{
DropDownList tmpDDL1 = ddl; // null
DropDownList tmpDDL2 = FindControl("ID"); // null
DropDownList tmpDDL3 = node.FindControl("ID"); // null
DropDownList tmpDDL4 = this.FindControl("ID"); // null
DropDownList tmpDDL5 = this.Page.FindControl("ID"); // null
DropDownList tmpDDL6 = fnFindControlRecursive(this, "ID"); // null
}
在畫面上還是看得到這個DDL
只是我抓不到它
想要給它設selected該怎麼辦呢
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 211.75.101.50
※ 文章網址: https://www.ptt.cc/bbs/Web_Design/M.1486635688.A.533.html
→ ssccg: control的event在LoadComplete前面,所以沒有 02/09 20:30
→ hirabbitt: 咦對耶 那我寫到Init去好了 02/10 08:51
→ te426odin: 有C#版喔! 02/10 09:16
→ hirabbitt: 好喔 02/10 11:33