[問題] ASP.NET找尋動態新增在Detailsview inserttemplate的物件

看板Web_Design作者 (Black J)時間15年前 (2011/03/19 00:09), 編輯推噓0(001)
留言1則, 1人參與, 最新討論串1/1
有個問題已經煩惱了二個工作天還是沒有頭緒 希望有人可以指點迷津 所有的表單接由Detailview物件用Insert模式包起來 程式片斷如下 <asp:detailsview id="dvMain" runat="server" mode="insert"> <fields> <asp:templatefield headertext="pid"> <inserttemplate> <asp:textbox id="tbPid" runat="server" autopostback="true" ontextchange="tbPid_textchange" /> </inserttemplate> </asp:templatefield> <asp:templatefield heradertext="reasonsTemplate" headerdisplay="false> <insertemplate> <%!-- 新物件產生的地方 ---%> </inserttemplate> </asp:templatefield> </field> </asp:detailsview> 新物件產生的方法 InsertTemplate template = WebUtil.GetDetailsTemplate("reasonsTemplate"); template.InsertTemplate = new InsertReasonsControl(FetchReasons(pid)); 結果,物件產生在預期產生的地方。因為Reasons是因為pid不同會有所不同,所以需要自已去 拼出Table物件,再動態產生在我預期產生的地方。 當使用者輸入資料後,我要去抓取Table中使用者輸入的值,我用了下列二個案例,一直找不 到動態產生的Table。 案例一 在dvMain_Init時,新增Table物件時,用dvMain.FindControl("tblReasons")會找的到物件 案例二 1)在tbPid_textchange時,新增Table物件時,用dvMain.FindControl("tbReasons")找不到物件 2) for(int idxCtl=0; idxCtl<dvMain.Rows.Count+1; idxCtl++) { var obj = dvMain.Rows[idxCtl].FindControl("tbReasons"); if (obj != null) break; } 用上列的程式碼還是找不到我新增的物件 NB: 1)在執行FindCode前我已經確認tblReasons已經存在,經由IE的ViewSource確認過 2)抓去detailsView資料的時間是dvMain_Inserting的事件中執行,其他非動態新增的物件 者抓的到。就唯有這個動態產生的物件都抓不到。 3)也用在DetailsView外加入<asp:Table>的物件,雖然抓的到它物件,但這個物件參考裡的的值是null 不存在任何值。 是不是,我抓取該動態物件的事件不對? 理論上網頁原始碼存在的資料,是抓的到的。希望有人可以 告訴我應該要怎麼做比較好。 謝謝! -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 115.64.139.214

03/28 15:33, , 1F
看不懂...
03/28 15:33, 1F
文章代碼(AID): #1DWuExCe (Web_Design)