C# 在设计器中添加了按钮引用,并在codebehind中抛出空错误
我的标记中有一个按钮,但在添加到页面设计器之前,在codebehind中无法访问该按钮。现在,当我运行该页面并检查一个ID以确定是否要启用或禁用按钮时,我会收到一个错误消息“Object reference not set to a instance of a Object”。我不知道它为什么扔那个 这是我输入到设计器中的代码,以便访问按钮C# 在设计器中添加了按钮引用,并在codebehind中抛出空错误,c#,asp.net,C#,Asp.net,我的标记中有一个按钮,但在添加到页面设计器之前,在codebehind中无法访问该按钮。现在,当我运行该页面并检查一个ID以确定是否要启用或禁用按钮时,我会收到一个错误消息“Object reference not set to a instance of a Object”。我不知道它为什么扔那个 这是我输入到设计器中的代码,以便访问按钮 /// <summary> /// Added this so i can access this button in the code beh
/// <summary>
/// Added this so i can access this button in the code behind
/// </summary>
protected global::DevExpress.Web.ASPxButton xbtnDelete;
/// <summary>
/// Added this so i can access it in the codebehind
/// </summary>
protected global::DevExpress.Web.ASPxButton xbtnView;
有没有关于我做错了什么的想法?找到了我做错的地方。我必须在网格的HTMLCreated事件中添加代码。这让我抓住了按钮
<dx:GridViewDataColumn VisibleIndex="0" Caption="" FieldName="Delete" Width="100" CellStyle-HorizontalAlign="Center">
<DataItemTemplate>
<dx:ASPxButton ID="xbtnDelete" runat="server" Text="Delete" OnClick="xbtnDelete_Click"
CommandArgument='<%# Container.VisibleIndex%>' Theme="Office2010Silver">
<Image IconID="edit_delete_16x16" ToolTip="Edit"></Image>
<ClientSideEvents Click="function(s, e) {e.processOnServer = confirm('Are you sure you want to delete this record?');}" />
</dx:ASPxButton>
</DataItemTemplate>
</dx:GridViewDataColumn>
<dx:GridViewDataColumn VisibleIndex="0" Caption="" FieldName="View" Width="100" CellStyle-HorizontalAlign="Center">
<DataItemTemplate>
<dx:ASPxButton ID="xbtnView" runat="server" Text="View" OnClick="xbtnView_Click"
CommandArgument='<%# Container.VisibleIndex%>' Theme="Office2010Silver">
<Image IconID="miscellaneous_viewonweb_16x16" ToolTip="Edit"></Image>
</dx:ASPxButton>
</DataItemTemplate>
</dx:GridViewDataColumn>
private void CheckRoleLevel(int roleid)
{
if (RoutingControler.CheckMyRolesAreHigherOrEqualThanComparedRole(Convert.ToInt32(roleid)).Equals(true))
{
xbtnDelete.Enabled = true;
xbtnView.Enabled = true;
}
else
{
xbtnDelete.Enabled = false;
xbtnView.Enabled = false;
}
}