Textbox inside a repeater even though it's hidden it is still being found, why?

480 Views Asked by At

This is weird and I'm scratching my head for hours now. I've a repeater with textbox (HTMLInputText), this textbox will be shown or hidden depends on data. I've scenario wherein, the first repeater item will show this textbox and the next repeater item will hide this textbox. I've a method that will loop through the repeater to get data and i'm checking this textbox if it is found or not just to indicate the status of each repeater item. The problem is, on the second repeater item wherein the textbox should not be found since it is hidden (display=none), i'm still finding it, i'm expecting to get nothing value. Checking on the html mark-up, the hidden textbox is not found there as expected. why oh why I'm not getting nothing? what is being returned is {value="0"} which is actually the initial value of the textbox. Please don't tell me to change my textbox to asp:textbox.

For each rptItem As RepeaterItem in repeater.Items
  dim tbx As HtmlInputText = rptItem.FindControl("tbxPrice")
  If tbx isNot Nothing Then
     'process here
  Else
     'another process
  End If
Next

I'm actually getting the correct data of the other items in the repeater.

EDIT: Additional codes HTML:

<div id="divTargetPrice" runat="server" visible="false">
  <input type="text" id="tbxPrice" runat="server" pattern="^\d+(?:\.\d\d?)?$" title="Valid amount in decimal number format (sample: 25.00)."
              value='<%#DataBinder.Eval(Container.DataItem, "Price", "{0:f2}")%>' />
</div>

Method:

Protected Sub repeater_ItemDataBound(sender As Object, e As RepeaterItemEventArgs) Handles repeater.ItemDataBound
  dim strRptItem = e.Item.DataItem("RangePrice").ToString
    Dim txtbox As New HtmlInputText
    If String.IsNullOrEmpty(strRptItem) Then
      e.Item.FindControl("divTargetPrice").Visible = True
    Else
      'e.Item.FindControl("divTargetPrice").Visible = False
      txtbox = e.Item.FindControl("tbxPrice")
      txtbox.Attributes.Add("display", "none")
    End If
  End If
End Sub

I tried changing the attribute of the textbox but the same result with the div being hidden.

1

There are 1 best solutions below

0
On

In your For-Each look, instead of looking tbx isnot nothing, look for one with the attribute display=none.