Click here to Skip to main content
16,004,778 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have this control and I want to write code for the click event for btnEdit. The problem is that I can't seem to be able to access btnSave from Visual Studio Debugger, any other ideas?

Articles.aspx
C#
<asp:FormView ID="Envelope" runat="server" DataSourceID="SqlDataSource1"
            AllowPaging="True"
            OnItemDeleted = "ArticleEnvelope_Deleted"
            OnItemInserted = "ArticleEnvelope_Inserted"
            OnItemUpdated = "ArticleEnvelope_Updated">
...
<itemtemplate>
...
&nbsp;<asp:Button enabled="true" ID="btnEdit" runat="server" Text="Edit" OnClick="btnEdit_Click" CommandName="Edit" />
...
</itemtemplate>


Articles.aspx.cs
C#
protected void btnEdit_Click(object sender, EventArgs e)
   {
        //btnSave.Enabled = true 
   }


I also tried iterating through Page.Controls, unsuccessfully , because it returns unmeaningful values:

C#
foreach (Control ctrl in Page.Controls)
       {
           TextBox1.Text = ctrl.ToString();
       }




:confused:

I'm using .NET 3.5 / VS 2008, and, the complete source code is available here.
Posted
Updated 30-Aug-10 8:45am
v2

1 solution

This is because 'btnSave' is part of the ItemTemplate you have used. You cannot directly access that contron in the page using this.

You need to loop through all the itemtemplates and use FindControl and then set it. Probably you want to disable for the row you edited data, so keep track of that row and accordingly access the row to disable the save button.
 
Share this answer
 
Comments
jon-80 30-Aug-10 16:15pm    
Any code snippets?
Christian Graus 30-Aug-10 17:19pm    
Google broken where you live ? This site has tons of articles with examples. At some point, you need to hope to become a programmer, able to follow instructions and read documentation, not just copy and paste 'code snippets'
jon-80 31-Aug-10 8:36am    
thanks for your comment, however, it's just that I haven't stumbled across the adequate solution for my problem, dude

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


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