2011-09-22 20 views
0
  • 我想要做的是從TextBox1中訪問該值以顯示回屏幕上。
  • 我試圖從Page_Load()和OnItemDataBound訪問它,它們都失敗了。
  • 看起來代碼能夠訪問控件,但它不返回任何內容。如何訪問Repeater FooterTemplate TextBox?

    保護無效的Page_Load(對象發件人,EventArgs的){

    Literal Literal1 = (Literal)Repeater1.Controls[Repeater1.Controls.Count - 1].FindControl("Literal1"); 
        Response.Write(Literal1.Text); 
        //this techique is not working for the line below 
        TextBox TextBox1 = (TextBox)Repeater1.Controls[Repeater1.Controls.Count - 1].FindControl("TextBox1"); 
        Response.Write(TextBox1.Text); 
    
    } 
    public void myRepeater_ItemDataBound(object sender, RepeaterItemEventArgs e) 
    { 
        //this techique is not working 
        if (e.Item.ItemType == ListItemType.Footer) 
        { 
         TextBox TextBox1 = (TextBox)e.Item.FindControl("TextBox1"); 
         Response.Write(TextBox1.Text); 
        } 
    } 
    
+0

你能顯示你的html嗎? – Lareau

+0

<表格ID = 「form1的」 RUNAT = 「服務器」> 的

 
Enter you text in the below to test.

+0

stackoverflow編輯器出錯。無法將代碼粘貼到原始帖子中。 –

回答

1

我不知道你所說的「他們都失敗了」,但如果文本框的Text屬性爲空是什麼意思我可能是因爲你在每個帖子後面都重寫了你的中繼器。嘗試使用!IsPostBack條件包裝您的中繼器.DataBind()。

0

我必須使用「文字」作爲替代解決方案通過傳遞HTML文本框問題。我不喜歡這個解決方案,但我想我必須使用它。

相關問題