我可以从内容页面隐藏母版页中的用户控件吗?(Can I hide a user control in a master page from a content page?)
如何从内容页面隐藏主页面上的用户控件? 这是我在内容页面加载时的代码。
Dim banner As UserControl = DirectCast(Master.FindControl("uc_banner1"), UserControl) banner.Visible = True
对我没有任何意义:(
How can I hide a user control on the master page from a content page? This is code I have on my content page's load.
Dim banner As UserControl = DirectCast(Master.FindControl("uc_banner1"), UserControl) banner.Visible = True
Does nothing for me :(
原文:https://stackoverflow.com/questions/3121915
最满意答案
import sys thismodule = sys.modules[__name__] setattr(thismodule, name, value)
或者,不使用
setattr
(它打破了问题的信,但满足相同的实际目的;-):globals()[name] = value
注意 :在模块范围内,后者相当于:
vars()[name] = value
这有点更简洁,但不能在函数内部运行(
vars()
给出了它在以下范围中调用的范围的变量:在全局范围调用时的模块变量,然后可以使用它R / W,但在函数中调用函数的变量,然后它必须被视为R / O - Python在线文档可能会有点混淆这个特定的区别)。import sys thismodule = sys.modules[__name__] setattr(thismodule, name, value)
or, without using
setattr
(which breaks the letter of the question but satisfies the same practical purposes;-):globals()[name] = value
Note: at module scope, the latter is equivalent to:
vars()[name] = value
which is a bit more concise, but doesn't work from within a function (
vars()
gives the variables of the scope it's called at: the module's variables when called at global scope, and then it's OK to use it R/W, but the function's variables when called in a function, and then it must be treated as R/O -- the Python online docs can be a bit confusing about this specific distinction).
相关问答
更多-
我已经分成了两步。 在第一步中,查询字符串被分解为一系列指令。 这样,问题就解耦了,我们可以在运行它们之前查看指令,并且不需要递归调用。 def build_instructions(obj, q): """ Breaks down a query string into a series of actionable instructions. Each instruction is a (_type, arg) tuple. arg -- The key used for ...
-
import sys thismodule = sys.modules[__name__] setattr(thismodule, name, value) 或者,不使用setattr (它打破了问题的信,但满足相同的实际目的;-): globals()[name] = value 注意 :在模块范围内,后者相当于: vars()[name] = value 这有点更简洁,但不能在函数内部运行( vars()给出了它在以下范围中调用的范围的变量:在全局范围调用时的模块变量,然后可以使用它R / W ...
-
Python已经包含了对包含类的广义委派的支持。 只需将MyClass的定义更改为: class MyClass: def __init__(self, someClass): self.refClass = someClass # Note: You call this someClass, but it's actually some object, not some class in your example def __getattr__ ...
-
第一个错误:无论如何,即使您实际设置了属性,也会raise AttributeError('Please stop trying!') 。 第二个错误:将type(self)传递给super是错误的,因为当类被子类化并且type(self)与您期望的类型不同时它会中断。 你不能使用0-argument super因为它依赖的__class__单元kludge仅在词法嵌套在类定义中的函数定义中被触发。 你必须让你的__setattr__明确地知道这个类,这个类甚至还没有被创建时很难。 一种选择是在类定义之后调 ...
-
我有一个特定的理由你这么复杂的方式吗? 为什么不这样做: def add_helpfunc(obj): def helpfunc(self): """Nice readable docstring""" #code obj.helpfunc = helpfunc 如果我没有错,以这种方式添加方法也可以解决您的帮助问题... 例: >>> class A: ... pass ... >>> add_helpfunc(A) >>> help(A.hel ...
-
“我认为如果对象具有hasOwnProperty他们也应该有一个getOwnProperty和一个setOwnProperty ” hasOwnProperty()函数告诉你,与作为对象原型链中某处的继承属性相比,命名属性是否作为对象的直接属性存在。 in运算符 - 用于像if (someProperty in someObject) {} - 会告诉您对象是否在原型链中的任何位置具有该属性。 你不需要相应的setOwnProperty()函数,因为你可以说: someObject[someProperty ...
-
接受并默默地放弃构造函数中的参数,如下所示: class FileConverter(sciluigi.Task): def __init__(self, *_args, **_kwargs): self.var = 'anything' Just for future reference, the answer to the isolated question, "How to... setattr(
, 'DynamicVar', sciluig ... -
这看起来很不错。 你可以使用属性。 三行代码: >>> class Class: ... def __init__(self, file_path, save_path=None): ... self.file_path=file_path ... self.save_path = save_path or file_path ... >>> c = Class('file') >>> c.file_path 'file' >>> c.save_path 'file ...
-
你建议的方法 globals()["var_name"] = value 确实是最恐怖的方式。 特别是,它比使用eval更加Pythonic,这将是你的主要(但不仅仅是)替代方案。 但是,如果您仍想使用setattr ,则可以使用sys.modules来获取对当前模块对象的引用,其中包含当前模块的__name__变量( 此处说明 ),如下所示: import sys setattr(sys.modules[__name__], "var_name", value) Your suggested appr ...
-
Python 2.7:对象.__ setattr__在幕后做了什么?(Python 2.7: What does object.__setattr__ do under the hood?)[2023-03-18]
object.__setattr__方法包括一个特定的检查,以确保传入的self实际上是对象的(子类)(或直接重用相同C函数的另一个对象)。 该测试不允许传入任何其他内容,包括旧式实例。 检查是为了防止object.__setattr__用于修改内置类型 (称为Carlo Verre hack,在其发现者之后)。 如果没有显式检查(或者如果你编译Python来禁用它),你可以这样做: >>> object.__setattr__(str, 'lower', str.upper) >>> "This is w ...