asp.net
  • vb.net
  • findcontrol
  • asprepeater
  • content-pages
  • 2017-08-30 7 views 0 likes 
    0

    リピータを必要とするように実行する非コンテンツ(マスターなし)ページがありますが、同じコードを(マスタを使用して)コンテンツページに移動すると、findControl RepeaterItemsのループ内で動作しなくなりました。repeater.findcontrolがコンテンツページ上で動作していません

    ASPX:

    <ItemTemplate> 
          <div class="row" id="qrow" runat="server" data-id='<%#Eval("callQuestionID") %>' data-type='<%#Eval("callQuestionResponseType") %>' data-parent='<%#Eval("callQuestionParent") %>'> 
           <div class="col-md-4"> 
            <asp:Label ID="questonTextLabel" runat="server" Text='<%# Eval("callQuestionText") %>'></asp:Label> 
           </div> 
           <div class="col-md-4"> 
            <asp:Panel ID="Panel1" runat="server"></asp:Panel> 
           </div> 
          </div> 
         </ItemTemplate> 
    

    ItemDataBound exerp

    Dim newRBY As New RadioButton 
           newRBY.InputAttributes.Add("data-id", CType(e.Item.DataItem, DataRowView)("callQuestionID")) 
           newRBY.InputAttributes.Add("data-idy", CType(e.Item.DataItem, DataRowView)("callQuestionID")) 
           newRBY.ID = "rby" 
           newRBY.Text = "Yes" 
           newRBY.GroupName = "qid" & CType(e.Item.DataItem, DataRowView)("callQuestionID") 
           CType(e.Item.FindControl("Panel1"), Panel).Controls.Add(newRBY) 
           Dim newRBN As New RadioButton 
           newRBN.InputAttributes.Add("data-id", CType(e.Item.DataItem, DataRowView)("callQuestionID")) 
           newRBN.InputAttributes.Add("data-idn", CType(e.Item.DataItem, DataRowView)("callQuestionID")) 
           newRBN.ID = "rbn" 
           newRBN.Text = "No" 
           newRBN.GroupName = "qid" & CType(e.Item.DataItem, DataRowView)("callQuestionID") 
           CType(e.Item.FindControl("Panel1"), Panel).Controls.Add(newRBN) 
    

    ポストユーザーとの対話処理:

    For Each questionRow As RepeaterItem In questionRepeater.Items 
        ... 
        Dim rby As RadioButton = CType(questionRow.FindControl("rby"), RadioButton) ****** Fails Here ***** 
           If rby.Checked Then 
            dataAccess.callQuestionAnswerTable_Insert(callIDInteger, CInt(rby.InputAttributes("data-id")), "true") 
           ElseIf CType(questionRow.FindControl("rbn"), RadioButton).Checked Then 
            dataAccess.callQuestionAnswerTable_Insert(callIDInteger, CInt(rby.InputAttributes("data-id")), "false") 
           End If 
    

    'RBY' を検索しようとしたときにそれはポストのユーザインタラクションの処理に失敗しました。生成されるHTMLの唯一の違いは、コンテンツページでは、コントロールIDがMainContent_接頭辞を取得することです。

    これを解決するにはどうすればよいですか?

    答えて

    0

    リピータがマスターページにあるときにコードが子ページにある場合は、マスターページをFindControlで指定し、そこにリピータを配置する必要があります。

    Dim rpt As Repeater = CType(Master.FindControl("Repeater1"),Repeater) 
    

    そして

    For Each questionRow As RepeaterItem In rpt.Items 
    

    (それは少しオフかもしれので、C#で、それはRepeater rpt = Master.FindControl("Repeater1") as Repeater;で、コードトランスレータでVBへのC#から翻訳)

    +0

    両方とも子ページにあります。唯一の違いは、環境のマスターページがあることです。 –

    0

    私は私の問題を発見しました。実際には、私はリピータのバインディングを持っていたのです。

    If Not IsPostBack Then 
    

    ブロックと私は明らかにすべきではありません。

    関連する問題