简体   繁体   English

将值从父页面传递到用户控件

[英]Passing Values From Parent Page To User Control

Hi i have a usercontrol embedded in multiple pages and i want to capture that from where that the usercontrol is loaded (from which parent page) 嗨,我有一个嵌入在多个页面中usercontrol ,我想从加载该usercontrol位置(从哪个父页面)捕获它

how to do this ? 这个怎么做 ? ,

Expose the thing as public Property than you able to access those in your child ones thats better way to do it 将事物公开为公共财产比您能够访问子财产中的财产更安全

search your child control form the parent like : parent.FindControl("Controlname") will do it 搜索您的子控件形式,例如: parent.FindControl("Controlname")会做到这一点

In your control, you can call CurrentExecutionFilePath which will provide you the path and page currently executing. 在您的控件中,您可以调用CurrentExecutionFilePath,它将为您提供当前正在执行的路径和页面。 If you're only interested in the filename, simply strip off the first part looking for LastIndexOf("/"). 如果您只对文件名感兴趣,只需删除第一部分以查找LastIndexOf(“ /”)。

从控件中,您可以调用Page.ToString() ,它应返回类似'ASP.TestPage_aspx'

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

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