浅谈ListView中的一个Bug
来源:互联网 发布:sdp 分销系统 源码 编辑:程序博客网 时间:2024/04/29 06:33
protected void ListView1_ItemCreated(object sender, ListViewItemEventArgs e) { if (e.Item.ItemType == ListViewItemType.InsertItem) { System.Web.UI.WebControls.DropDownList ddlLinkType = (System.Web.UI.WebControls.DropDownList)e.Item.FindControl("DropDownListLinkType"); if (ddlLinkType != null) { TextBox LogoUrlTextBox = (TextBox)e.Item.FindControl("LogoUrlTextBox");
if (LogoUrlTextBox != null) { ddlLinkType.Attributes["onchange"] = "ddlonchange(this,'" + LogoUrlTextBox.ClientID + "')"; } } } }
1.在后台为前台控件添加javascript注册事件,发现数据无法“插入”、“更改”。
ddlLinkType.Attributes["onchange"] = "ddlonchange(this,'" + LogoUrlTextBox.ClientID + "')";
2.注销该代码程序又可以进行“插入”、“更改”。
<tr style=""> <td> <input type="submit" name="ctrl1$InsertButton" value="插入" onclick="javascript:WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions("ctrl1$InsertButton", "", true, "Insert", "", false, false))" id="ctrl1_InsertButton" /> <input type="submit" name="ctrl1$CancelButton" value="清除" id="ctrl1_CancelButton" /> </td> <td> </td> <td> <input name="ctrl1$SiteNameTextBox" type="text" id="ctrl1_SiteNameTextBox" /> <span id="ctrl1_RequiredFieldValidator1" style="color:Red;visibility:hidden;">*</span> </td> <td> <select name="ctrl1$insertddlLinkType" id="ctrl1_insertddlLinkType" onchange="ddlonchange(this,'ctrl1_LogoUrlTextBox')"><option value="LogoLink">图片连接</option><option value="TextLink">文本连接</option></select> </td> <td> <input name="ctrl1$LogoUrlTextBox" type="text" id="ctrl1_LogoUrlTextBox" /> </td> <td> <input name="ctrl1$SiteUrlTextBox" type="text" id="ctrl1_SiteUrlTextBox" /> <span id="ctrl1_RequiredFieldValidator2" style="color:Red;visibility:hidden;">*</span> </td> </tr>
3.查看渲染到浏览器的代码,发现InsertItemTemplate里的所有ID号都缺少"ListView_"前缀。通过对事件分析,ListView创建前触发了ItemCreated事件,在事件里使用ClientID
导致了InsertItemTemplate模块中的控件渲染到浏览器端后的id值就没有“ListView1_”这个前缀,点击按钮,就无法把数据插入到ListView里。
4.在微软也发布了这个Bug
文章地址:http://connect.microsoft.com/VisualStudio/feedback/details/328680/problem-accessing-controls-clientid-on-asp-net-listviews-itemcreated
5.经过分析,可以将注册到InsertItemTemplate的事件代码放到dataBound中运行,应为当运行到InsertItemTemplate时,就会调用此事件
public static Control FindControl(string controlId, ControlCollection controls) { foreach (Control control in controls) { if (control.ID == controlId) return control; if (control.HasControls()) { Control nestedControl = FindControl(controlId, control.Controls); if (nestedControl != null) return nestedControl; } } return null; } protected void ListView1_DataBound(object sender, EventArgs e) { System.Web.UI.WebControls.DropDownList ddlLinkType = FindControl("insertddlLinkType", ListView1.Controls) as System.Web.UI.WebControls.DropDownList; TextBox LogoUrlTextBox = (TextBox)FindControl("LogoUrlTextBox", ListView1.Controls); RequiredFieldValidator validator = FindControl("RequiredFieldValidator1", ListView1.Controls) as RequiredFieldValidator; if (ddlLinkType != null && LogoUrlTextBox != null && validator != null) { ddlLinkType.Attributes["onchange"] = "ddlonchange(this,'" + LogoUrlTextBox.ClientID + "','" + validator.ClientID + "')"; } }
6.采用微软的解决方案。。很好的处理这个难题,,到了.NET4.0也没有处理这个Bug,以后可以采用这样的办法处理。
- 浅谈ListView中的一个Bug
- ListView 中的一个低级 BUG
- ListView中的bug
- VS2010中的ListView的BUG
- VS2010中的ListView的BUG
- Cg中的一个Bug
- IE7中的一个bug
- ipconntrack中的一个BUG
- 违例中的一个BUG
- NALDecoder中的一个bug
- asp.net中ListView的一个Bug
- 关于ListView和ViewPager的一个Bug
- CSDN圈子中的一个BUG
- 建行业务中的一个BUG
- J2ME中的一个小BUG
- netty中的一个小bug
- STLport源代码中的一个BUG
- 浅谈Android控件中的ListView优化
- fedora之无限折腾—— >快捷安装+配置
- 编程的收获
- 改错题
- 你需要知道的16个Linux服务器监控命令
- LGA1155、LGA1156、LGA1366、LGA2011的CPU插槽对应的都是什么型号的CPU
- 浅谈ListView中的一个Bug
- 关于free type
- ActivityGroup简介
- 实验四:随机生成图形
- C# 设置文件夹访问权限
- JavaScript元素type属性达到预加载但不执行的效果
- 第六周任务3:平面坐标点类
- 显示各位数
- 网络监控系统,产品自带的免费客户端和管理平台的区别?