首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

点击按钮让所有控件Enable全为False(用javascript),该如何解决

2011-12-31 
点击按钮让所有控件Enable全为False(用javascript)我在Asp.net的用户控件里,我想用javascript实现,当点击B

点击按钮让所有控件Enable全为False(用javascript)
我在Asp.net的用户控件里,我想用javascript实现,当点击Button(btnSave)时,所有按钮的Enable都为False,试了多次都不行,但在不是用户控件的页面就行.就用

JScript code
document.getElementById("txtCode").disabled=true;
.但在用户控件就是不行.请大家帮看下...代码如下:
HTML code
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="AcademyUC.ascx.cs" Inherits="manager_UserControl_AcademyUC" %><script language="javascript" type="text/javascript"><!--function btnAdd_onclick() {    document.getElementById("txtCode").disabled=true;}// --></script><table width="658" height="180" border="1"> <tr>    <td colspan="4" bgcolor="lavender"><center>        学院信息</center></td>  </tr>  <tr>    <td colspan="4" style="height: 26px">        &nbsp;        <input id="btnAdd" style="position: relative" type="button" value="增加" language="javascript" onclick="return btnAdd_onclick()" />        &nbsp;<asp:Button            ID="btnModify" runat="server" Style="position: relative" Text="修改" />&nbsp;<asp:Button                ID="btnDelete" runat="server" Style="position: relative" Text="删除" />        <asp:Button ID="btnSave" runat="server" Style="position: relative" Text="保存" OnClick="btnSave_Click" />        <asp:Button ID="btnCancel" runat="server" Style="position: relative" Text="取消" />        </td>  </tr>  <tr>    <td>&nbsp;编号:</td>    <td>&nbsp;<asp:TextBox ID="txtCode" runat="server" Style="position: relative; left: 1px; top: -2px;" ></asp:TextBox></td>      <td rowspan="2">          备注:&nbsp;</td>      <td rowspan="2">          &nbsp;          <asp:TextBox ID="txtRemarks" runat="server" Height="54px" Style="left: -5px; position: relative; top: 1px;"              TextMode="MultiLine" Width="210px"></asp:TextBox></td>  </tr>  <tr>    <td>&nbsp;名称:</td>    <td>&nbsp;<asp:TextBox ID="txtName" runat="server" Style="position: relative; left: 2px; top: 0px;"></asp:TextBox>*</td>  </tr>  <tr>    <td colspan="4" bgcolor="lavender"><center>        &nbsp;</center></td>  </tr>  <tr>    <td colspan="4">&nbsp;<asp:GridView ID="GridView1" runat="server" Style="position: relative" BackColor="White" BorderColor="#CCCCCC" BorderStyle="None" BorderWidth="1px" CellPadding="3" AutoGenerateColumns="False" >        <FooterStyle BackColor="White" ForeColor="#000066" />        <RowStyle ForeColor="#000066" />        <Columns>            <asp:CommandField ShowDeleteButton="True" />            <asp:BoundField DataField="AcademyCode" HeaderText="编号" />            <asp:BoundField DataField="AcademyName" HeaderText="名称" />            <asp:BoundField DataField="Remarks" HeaderText="备注" />        </Columns>        <PagerStyle BackColor="White" ForeColor="#000066" HorizontalAlign="Left" />        <SelectedRowStyle BackColor="#669999" Font-Bold="True" ForeColor="White" />        <HeaderStyle BackColor="#006699" Font-Bold="True" ForeColor="White" />        </asp:GridView>        &nbsp;</td>  </tr></table> 



[解决办法]
function DisableAllControls(){
var ctls=document.getElementsByTagName("INPUT");
if(ctls){
for(var i=0;i<ctls.length;i++){
ctls[i].disabled=true;} 

}

试试这个
[解决办法]
加一个类型判断
function DisableAllControls(){ 
var ctls=document.getElementsByTagName("INPUT"); 
if(ctls){ 
for(var i=0;i <ctls.length;i++){ 
if(ctls[i].type=='text')
ctls[i].disabled=true;} 

}

热点排行