0

My problem was asked to you before but I cannot make it work. I need your help, I think.

<asp:ListView runat="server" ID="listvsl">
    <ItemTemplate>
        <td>
            <img style="width: 100%; height: 150px;" src="<%#Eval("resim") %>" /><br />
            <asp:Button ID="in" runat="server" Text="Sol" ClientIDMode="Inherit" OnClick="haraket" Style="width: 75px;" />
            <asp:Button ID="cik" OnClick="haraket" runat="server" Text="Sağ" Style="width: 75px;" /><br />
            <asp:Button ID="Button10" runat="server" Text="Sil" OnClick="sil_Clickice" Style="width: 150px;" /><br />
            <asp:TextBox ID="aciklax" runat="server" TextMode="MultiLine" ClientIDMode="Inherit" /><br />
            <asp:Button ID="Button12" runat="server" Text="Güncelle" ClientIDMode="Inherit" OnClick="yazignc" />
        </td>
    </ItemTemplate>
</asp:ListView>

I need to get the aciklax TextBox with FindControl when I click "Button12"

Button bu = (Button)sender;//Button12's onclick event
string[] falanca = bu.ClientID.ToString().Split('_');
string alcez = falanca[0] + "_" + falanca[1] + "_" + "aciklax" + "_" + falanca[3];

This is my method to find the ClientId. I get the ClientId but I cannot get the TextBox control with it. Can you help me ?

ConnorsFan
  • 70,558
  • 13
  • 122
  • 146
  • Be careful to format your code and your markup correctly when you ask a question. It helps to understand what you did and what you are trying to achieve. – ConnorsFan May 29 '16 at 03:05

1 Answers1

2

Fortunately, you don't need to parse the ClientID to find the TextBox control. You can use the NamingContainer property of the button to find the corresponding ListView item. Then you can find the TextBox in the item, using the original ID specified in the ItemTemplate:

Button btn = sender as Button;
ListViewItem item = btn.NamingContainer as ListViewItem;
TextBox txt = item.FindControl("aciklax") as TextBox;
ConnorsFan
  • 70,558
  • 13
  • 122
  • 146
  • this is really magical solution thank you , but i really do not understood english part i am low in english , can you explain it to me easiest language ? – Uğur Canbulat May 29 '16 at 10:12
  • You are welcome. My best explanation is the code. In short: from the button you can get the item, and from the item you can get the TextBox. – ConnorsFan May 29 '16 at 10:16
  • i do not know this method exist really thank you , but i need one more thing how can i show "aciklax" 's saved value ? – Uğur Canbulat May 29 '16 at 10:24
  • i try Eval method Text="<%# Eval("aciklax's value") %>" but ISS warn me – Uğur Canbulat May 29 '16 at 10:26
  • If the field is called "aciklax", you can fill the TextBox with `Text='<%# Eval("aciklax") %>'`. Please note the outer single quotes `'` and the inner double quotes `"`. (One more note: if the answer solved your problem, you can accept it with the check mark). – ConnorsFan May 29 '16 at 10:30
  • thank you again note : i was not know how to accept the answer sorry :) found and clicked the accept button – Uğur Canbulat May 29 '16 at 10:34
  • That's OK. And thank you! Most newcomers don't know that they should accept an answer. :-) – ConnorsFan May 29 '16 at 10:37