c# - 无法从 UserControl 上的字符串表示错误创建 System.Guid 类型的对象

标签 c# asp.net user-controls

在 .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/

相关文章:

c# - 从 DataTable 获取单个值的最佳方法?

c# - EventAggregator 仅适用于 MVVM 中的 ViewModels 吗?

c# - 无法使用 C# 使用 ExcelPackage 创建带撇号的 XLSX

.net - Windows 窗体 : Using a user control like a container control

wpf - AvalonDock + UserControl + DataGrid + ContextMenu 命令路由问题

c# - 为什么在从 ASMX Web 方法返回派生类对象时我的基类字段没有被序列化?

asp.net - 升级到 ASP.NET MVC 版本 2

c# - 如何更改自定义字段(\Areas\Identity\Pages\Account\Manage\Index.cshtml.c)的值?

c# - 在 C# 中使用 WebRequest 和 WebResponse 类登录

.net - 在.net中查找控件