English 中文(简体)
ASP.NET 找到其他控制范围内的控制办法是否更好?
原标题:ASP.NET Is there a better way to find controls that are within other controls?

目前,我被降为 as。 我需要从同一页的另一条轴上后面的代码中“确定”。 该数值作为目标2的参考值。 目前,我正在使用这一简略的法典。 它发挥作用,但我认识到,如果侵权行为令要改变或改变其他各种事情,那就不是我所期望的。 是否有任何人建议我应如何适当这样做?

if(Page is ClaimBase)
{
  var p = Page as ClaimBase;
  var controls = p.Controls[0].Controls[3].Controls[2].Controls[7].Controls[0];
  var ddl = controls.FindControl("ddCovCert") as DropDownList;
}

Thanks and Happy New Year!! ~ck in San Diego

最佳回答

一般来说,如果你发现控制情况很多,我就执行“FindInPage”或休养性“FindInPage”功能,那儿,你只是通过控制,会 rec弃控制树。

如果这只是一件一件事,则考虑在您的APIC中披露你所需要的控制权,以便你能够直接查阅。

public static Control DeepFindControl(Control c, string id)
{
   if (c.ID == id)
   { 
     return c;
   }
   if (c.HasControls)
   {
      Control temp;
      foreach (var subcontrol in c.Controls)
      {
          temp = DeepFindControl(subcontrol, id);
          if (temp != null)
          {
              return temp; 
          }
      }
   }
   return null;
}
问题回答

• 在用户控制类别上获取财产,退还所需价值。 让我们能够查阅财产。

只有用户控制才能知道其中有哪些控制措施。





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Transaction handling with TransactionScope

I am implementing Transaction using TransactionScope with the help this MSDN article http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx I just want to confirm that is ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

Microsoft.Contracts namespace

For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts;?

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签