在 .aspx 页面上注册我的用户控件,如下所示:
<uc:MyControl Id="MyControlId" runat="server"></uc:MyControl>
我正在 .aspx 页面的代码隐藏中使用属于此用户控件的方法:
MyControlId.MyMethod();
但是我在解析时遇到此错误:“无法从“Id”属性的字符串表示形式“MyControlId”创建“System.Guid”类型的对象”。我该如何解决这个问题?
注意:这不是我正在寻找的解决方案:Cannot create an object of type 'System.Object' from its string representation
用户控件中的MyMethod():
public void MyMethod()
{
BindInfo();
InfoArea.Style.Add("display", "block");
}
最佳答案
我找到了真正的解决方案。我的用户控件界面中有一个名为“Id”的 Guid 属性。因此,接口(interface)成员“Id”与用户控件的 Id 属性冲突。更改接口(interface)成员的名称解决了问题。
关于c# - 无法从 UserControl 上的字符串表示错误创建 System.Guid 类型的对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26464999/