gpt4 book ai didi

c# - 在后面的代码中找出哪个页面使用用户控件

转载 作者:太空宇宙 更新时间:2023-11-03 20:27:27 25 4
gpt4 key购买 nike

在我的应用程序中,我为两个页面使用用户控件:AddInfo.aspx 和 EditInfo.aspx。

问题是我希望在保存信息时发生不同的事情,这取决于用户所在的页面(即他实际在做什么)。

所以我想知道是否有任何方法可以使用 if 语句找出当前正在使用用户控件的页面?这样我的问题就可以解决了。

protected void SaveButton_Click(object sender, EventArgs e) {

if (//The page using the usercontrol = Edit.aspx) {
// do this...
}
else {
// do that...
}
}

提前致谢

最佳答案

protected void SaveButton_Click(object sender, EventArgs e) {

if (this.Page is EditInfo) {
// do this...
}
else {
// do that...
}
}

EditInfo 是您页面的类。

您还可以在您的用户控件上定义一个 Behavior 属性,并根据您在哪个页面中的需要在您的 Xaml 代码中设置它。这是避免需要知道您所在位置的好方法。

关于c# - 在后面的代码中找出哪个页面使用用户控件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9729949/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com