<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN" "http://www.wapforum.org/DTD/wml_1.1.xml">
<wml>
<head><meta forua="true" http-equiv="Cache-Control" content="max-age=0" /></head>
<card title="控件查找-控件访问有用的方法" id="card1">
<p> 游客</p><p>
标题:控件查找-控件访问有用的方法<br/>
正文:<br/>
 今天找了较长时间，老是用遍历的方法，很是费时间。如果不是对控件逐个操作，完全可以用这个方法。这里记录一下，用来在页面或者其他容器控件中找其他控件。vb或者C#、C shap中的控件查找，尤其是当动态生成了控件ID的时候，就需要这个，适合asp.net或.net Framework的windows应用程序。The following example defines a Button1_Click event handler. When invoked, this handler uses the FindControl method to locate a control with an ID property of TextBox2 on the containing page. If the control is found, its parent is determined using the Parent property and the parent control's ID is written to the page. If TextBox2 is not found, &amp;quot;Control Not Found&amp;quot; is written to the page.Security NoteThis example has a text box that accepts user input, which is a potential security threat. By default, ASP.NET Web pages validate that user input does not include script or HTML elements. For more information, see Script Exploits Overview.C#代码：private void Button1_Click(object sender, EventArgs MyEventArgs){      // Find control on page.      Control myControl1 = FindControl(&amp;quot;TextBox2&amp;quot;)<br/><a href="http://www.zhongguosou.com/blog/wap.asp?mode=WAP&amp;act=View&amp;id=703&amp;Page=1">[&lt;&lt;]</a><a href="http://www.zhongguosou.com/blog/wap.asp?mode=WAP&amp;act=View&amp;id=703&amp;Page=1">[[1]]</a><a href="http://www.zhongguosou.com/blog/wap.asp?mode=WAP&amp;act=View&amp;id=703&amp;Page=2">[2]</a><a href="http://www.zhongguosou.com/blog/wap.asp?mode=WAP&amp;act=View&amp;id=703&amp;Page=3">[3]</a><a href="http://www.zhongguosou.com/blog/wap.asp?mode=WAP&amp;act=View&amp;id=703&amp;Page=3">[&gt;&gt;]</a><br/>
<br/>
<a href="wap.asp?act=Com&amp;id=703">查看评论(0)</a><br/>
<a href="wap.asp?act=AddCom&amp;inpId=703">发表评论</a><br/><br/>

<br/>

<br/>
<a href="http://www.zhongguosou.com/blog/wap.asp">首页</a>
</p>
</card>
</wml>