如何找到使用asp.net创建了Java脚本动态控制 [英] How to find Dynamic control in Java Script created using asp.net

查看:135
本文介绍了如何找到使用asp.net创建了Java脚本动态控制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经创建了ASP.NET动态控件如下..

I have created dynamic controls in ASP.NET as following ..

首先我创建复选框为

 CheckBox chkDynamic = new CheckBox(); 

然后

 TextBox txtDynamic = new TextBox();
 txtDynamic.ID = "txtDynamic";

和这些控件中的TableRow添加的TableCell表添加加入aspPanel增加(仅面板在设计页面中创建)

and these controls added in tablecell added in tableRow added in Table added in aspPanel(Only panel created at design page)

现在我需要..被选中的复选框,当我想清楚使用JavaScript txtDynamic文本框

我尝试以下方法,但不工作。

I tried following ways but not working..

 chkDynamic.Attributes["onclick"] = "javascript:document.getElementById('" + txtDynamic.UniqueID + "').value='';";

我也试图与调用方法

also i tried with calling Method as

 chkDynamic.Attributes.Add("onclick", "javascript:ClearText(this)");

但在这种方法下行给我错误未找到txtDynamic..因为控制添加dynamicaly。

but in this method following line giving me error not found "txtDynamic".. because the control added dynamicaly.

 document.getElementById("<%= txtDynamic.ClientID %>").value="";

在此先感谢....

Thanks in advance....

推荐答案

经过大量的调试我喜欢的答案。什么是ASP.Net在做此之前我在末尾加上整个表它改变了控制的ClientID的连接与父控件的一些preFIX运行时间的所有TR现在创造了什么,我没有解决这个我已经添加了表面板 plDynamicControls.Controls.Add(tblGeneralControls); 然后我说下code和它的作品般的魅力

After lots of debug i fond the answer. What does ASP.Net do at the run time it changes the ClientID of the control with attaching the parent control some prefix so before i added the entire table at the end of the all the TR created now what i did to solve this i have added the table to panel as plDynamicControls.Controls.Add(tblGeneralControls); then i added following code and it works like charm

chkDynamic.Attributes["onclick"] = string.Format("yearSuffixCHK(this, '{0}')", txtDynamic.ClientID);
txtDynamic.Attributes["onchange"] = string.Format("yearSuffixTXT(this, '{0}')", chkDynamic.ClientID);

这篇关于如何找到使用asp.net创建了Java脚本动态控制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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