【问题标题】:find dynamic added panel查找动态添加面板
【发布时间】:2016-05-04 16:13:49
【问题描述】:

我正在向我的 Web 应用程序添加这样的面板:

For i = 1 To amountOfRechnungspositionen + 1 
  Dim pnlPositon As Panel = New Panel
  pnlPositon.ID = "pnlPositon" & i
  pnlRechungsposition.Controls.Add(pnlPositon)
   ... 
Next

现在如果我点击一个按钮,我想删除这个面板。 这是我的代码。

Private Sub imgDelRechnungsPosition_Click(sender As Object, e As ImageClickEventArgs) Handles imgDelRechnungsPosition.Click

    amountOfRechnungspositionen = Convert.ToInt32(hfAmountofRechnungspositionen.Value)

    Dim fcpnlPositon As Panel = DirectCast(pnlRechungsposition.FindControl("placeholderID$pnlPositon" + amountOfRechnungspositionen.ToString()), Panel)
    fcpnlPositon.Dispose()

    hfAmountofRechnungspositionen.Value = Convert.ToString(amountOfRechnungspositionen - 1)

End Sub

但是 fcpnlPositon 什么都不是。 我做错了什么?

感谢您的阅读。

【问题讨论】:

  • 您是否在每次回发时都添加面板?请记住,每次回发后动态控件都会丢失
  • 在回发时我这样做:如果不是 IsPostBack Then genNeueRechnungsPosition() End If EDIT: Oh sry function genNeueRechnungsPosition 是添加面板的函数
  • 什么是genNeueRechnungsPosition?可能是动态添加面板的方法?所以是的,您不会在每次回发时都添加它们吗?
  • 是的,我不会在每次回发时都添加它们。抱歉,我按了 Enter 并没有准备好输入

标签: asp.net vb.net dynamic panel


【解决方案1】:

尝试使用:

CType(pnlRechungsposition.FindControl("pnlPositon" + 
           amountOfRechnungspositionen.ToString()), Panel)

占位符文本仅用于客户端标记,因此您希望使用直接 ID 属性。

【讨论】:

  • 您每次都在重新构建页面 init 上的面板列表,对吗?什么是 pnlRechungsposition.Controls.Count 属性从按钮单击中返回。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-07-22
  • 2012-08-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多