Button.Enable ="true/false"; -启用/禁用其中的按钮 [英] Button.Enable = "true/false" - enabling / disabling buttons within

查看:193
本文介绍了Button.Enable ="true/false"; -启用/禁用其中的按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我拥有此控件,我想为 btnEdit 的click事件编写代码.问题是我似乎无法从Visual Studio调试器访问btnSave,还有其他想法吗?

Articles.aspx

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

<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



Articles.aspx.cs

protected void btnEdit_Click(object sender, EventArgs e)
   {
        //btnSave.Enabled = true 
   }



我还尝试遍历Page.Controls,但未成功,因为它返回了无意义的值:



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

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





:confused:

我正在使用.NET 3.5/VS 2008,并且完整的源代码可用





:confused:

I''m using .NET 3.5 / VS 2008, and, the complete source code is available here.

推荐答案

这是因为"btnSave"是您使用的ItemTemplate.您不能使用此方法直接在页面中访问该contron.

您需要遍历所有itemtemplates并使用FindControl,然后进行设置.可能您想禁用已编辑数据的行,因此请跟踪该行并相应地访问该行以禁用保存按钮.
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.


这篇关于Button.Enable ="true/false"; -启用/禁用其中的按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆