Click here to Skip to main content
14,494,810 members
Rate this:
Please Sign up or sign in to vote.
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
Rate this:
Please Sign up or sign in to vote.

Solution 1

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");
      }
}
   
Rate this:
Please Sign up or sign in to vote.

Solution 2

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
   
v3

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




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100