简体   繁体   English

从父级访问用户控制

[英]Access User Control from Parent

On the HomePage.aspx, i have a usercontrol, Product.acsx on this control have another user control ProductDetails.acsx.在 HomePage.aspx 上,我有一个用户控件,Product.acsx 在这个控件上还有另一个用户控件 ProductDetails.acsx。 ProductDetails has a textbox, txtDescription. ProductDetails 有一个文本框 txtDescription。 Product.ascx has a dropdown Products. Product.ascx 有一个下拉产品。 I am populating the Products dropdown from HomePage.aspx.我正在填充 HomePage.aspx 中的产品下拉列表。 By default first value is selected, there is no empty value.默认选择第一个值,没有空值。 If the first value which is auto selected is Electronics, then i need to disable the textbox: txtDescription on the ProductDetails.acsx.如果自动选择的第一个值是 Electronics,那么我需要禁用文本框:ProductDetails.acsx 上的 txtDescription。 How to access txtDescription on HomePage.aspx.如何访问 HomePage.aspx 上的 txtDescription。

2nd Approach: By the time Product.acsx is loaded Electronics is selected in the dropdown, how to make txtDescription disabled.第二种方法:加载 Product.acsx 时,在下拉列表中选择了 Electronics,如何禁用 txtDescription。

Note: Dropdown has other values, Returns, Enquiry, Electronics, Home Appliances.注意:Dropdown 有其他值,Returns,Enquiry,Electronics,Home Appliances。 It's not necessary Electronics is always the first value.电子产品不一定是第一价值。

Created a public method M1() in Product.acsx.cs and exposed it to HomePage.aspx.cs.在 Product.acsx.cs 中创建了一个公共方法 M1() 并将其公开给 HomePage.aspx.cs。 M1() has access to the textbox: txtDescription. M1() 可以访问文本框:txtDescription。

Please share if you have better approach.如果您有更好的方法,请分享。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM