猿问

ListView控件,加一个客户端的JS代码,就不能插入、更新了!?

需求:一个用户表 字段为 名字,年龄 和性别 (性别是CheckBox ),要求:CheckBox 选中时为男性,不必填写年龄,(即插入项,年龄输入框隐藏,[color=#FF6600]用js实现[/color])不选中时为女,年龄框可见,

js和程序效果我都实现了,奇哉怪也的是:InputAttributes["onchange"] = "changeed(this,'" + txtage.ClientID + "')";时, 插入,更新都不可用了!!即在 编辑、插入时,填好数据后,点更新或插入,数据会被清空,且维持编辑状态不变,经探索:毛病出在 "changeed(this,'" + txtage.ClientID + "')"; 把此javascript函数的形式改一下 即 不用txtage.ClientID 或其他字符串时,该现象就会消失!!
不知所以然,望高手指教
我的源代码在:http://www.w8le.com/lkfup/Solution1.rar

 

        protected void ListView1_ItemCreated(object sender, ListViewItemEventArgs e)
        {
            if (e.Item.ItemType == ListViewItemType.DataItem || e.Item.ItemType == ListViewItemType.InsertItem)
            {
                CheckBox chb = e.Item.FindControl("UserGenderCheckBox") as CheckBox;
                TextBox txtage = e.Item.FindControl("UserAgeTextBox") as TextBox;
                if (chb != null && txtage !=null)
                {
                    //chb.Attributes["onchange"] = "changeed(this,'" + txtage.ClientID + "')"; 
                    chb.InputAttributes["onchange"] = "changeed(this,'" + txtage.ClientID + "')";
                }
            }
        }
郎朗坤
浏览 497回答 1
1回答
随时随地看视频慕课网APP

相关分类

JavaScript
我要回答