Click here to Skip to main content
15,886,689 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
hi i want change text of ont button with find control method in c#?
how i can it?
tnx
Posted
Updated 24-Jan-20 5:38am
Comments
CodeBlack 17-Oct-13 2:59am    
can you update your question with more explanation and source code ?
Harshil_Raval 17-Oct-13 3:18am    
Please be more specific about your question. Update your question with more detail.
JoCodes 17-Oct-13 3:48am    
Not clear at all . Please improve your question on what you want exactly if possible with some source code

private void Button1_Click(object sender, EventArgs MyEventArgs)
{
      // Find control on page.
      Control myControl1 = FindControl("TextBox2");
      if(myControl1!=null)
      {
         // Get control's parent.
         Control myControl2 = myControl1.Parent;
         Response.Write("Parent of the text box is : " + myControl2.ID);
      }
      else
      {
         Response.Write("Control not found");
      }
}
 
Share this answer
 
You can change the text of a GridView Control like this

.aspx
<asp:GridView ID="GridView1" runat="server">
    <Columns>
        <asp:TemplateField>
            <ItemTemplate>
                <asp:Button id="Button1" runat="server" Text="Hello World!"/>
            </ItemTemplate>
        </asp:TemplateField>
    </Columns>
</asp:GridView>


.cs
foreach (GridViewRow row in GridView1.Rows)
{
    if (row.RowType == DataControlRowType.DataRow)
    {
        Button btn = e.Row.FindControl("Button1") as Button;
        btn.Text = "Goodbye World!";

    }
}


You can add this cs to any function
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900