Can somebody tell me how I get this error?
here is a snippet of the code:
<span class="Normal">
<asp:Label runat="Server" Text='<%# DataBinder.Eval(Container.DataItem,"CreatedByUser") %>' ID="Label1"/>
</span>
<% if (Context.User.Identity.Name == Label1.Text) { %>
<asp:HyperLink id="editLink" ImageUrl="~/images/edit.gif" NavigateUrl='<%# "~/DesktopModules/EditAnnouncements.aspx?ItemID=" + DataBinder.Eval(Container.DataItem,"ItemID") + "&mid=" + ModuleId %>' Visible="<%# IsEditable %>" runat="server" />
<% } %>
<span class="ItemTitle">
<%# DataBinder.Eval(Container.DataItem,"Title") %>
</span
and here is the compiler error:
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
Line 9: <asp:Label runat="Server" Text='<%# DataBinder.Eval(Container.DataItem,"CreatedByUser") %>' ID="Label1"/>
Line 10: </span>
Line 11: [RED MARKED]<% if (Context.User.Identity.Name == Label1.Text) { %>[\RED MARKED]
Line 12: <asp:HyperLink id="editLink" ImageUrl="~/images/edit.gif" NavigateUrl='<%# "~/DesktopModules/EditAnnouncements.aspx?ItemID=" + DataBinder.Eval(Container.DataItem,"ItemID") + "&mid=" + ModuleId %>' Visible="<%# IsEditable %>" runat="server" />
Line 13: <% } %
Hope you can help me
regards
delleNullReferenceException's usually occur (in my experience anyway) when you have programmed an event to occur and presumed a variable/data source will be available and (for one of many possible reasons) it isn't.
I see you are using a databound control - have you told the control where to get it's data from? have called the DataBind event of the control?
Could you give us a bit more code?
Which line in the code is it telling you is causing this error?
You have to check Context.User for null before use
Hi,
Now I'm checking the value "Context.User.Identity.Name" for "null".
This was one problem I guess, because now I can build the project without an error,
but when I log in I still become an error.
I replaced my variables with constants to see if the function would work, and yes it is working.
The problem is that the value of Label1.Text cannot be compared with "Context.User.Identity.Name" for some reason.
Here is the new code:
<span class="Normal">
<%# DataBinder.Eval(Container.DataItem,"CreatedByUser") %>
<asp:Label runat="Server" Text='<%# DataBinder.Eval(Container.DataItem,"CreatedByUser") %>' ID="Label1"/>
</span>
<% if (Context.User.Identity.Name != "") { %>
<% if (Context.User.Identity.Name == Label1.Text) { %>
<asp:HyperLink id="editLink" ImageUrl="~/images/edit.gif" NavigateUrl='<%# "~/DesktopModules/EditAnnouncements.aspx?ItemID=" + DataBinder.Eval(Container.DataItem,"ItemID") + "&mid=" + ModuleId %>' Visible="<%# IsEditable %>" runat="server" />
<% } %>
<% } %>
<span class="ItemTitle">
<%# DataBinder.Eval(Container.DataItem,"Title") %>
</span
The error the compiler gives me is still the same in line 12:
Line 10: </span>
Line 11: <% if (Context.User.Identity.Name != "") { %>
Line 12: <% if (Context.User.Identity.Name == Convert.ToString(Label1.Text)) { %>
Line 13: <asp:HyperLink id="editLink" ImageUrl="~/images/edit.gif" NavigateUrl='<%# "~/DesktopModules/EditAnnouncements.aspx?ItemID=" + DataBinder.Eval(Container.DataItem,"ItemID") + "&mid=" + ModuleId %>' Visible="<%# IsEditable %>" runat="server" />
Line 14: <% } %
Suggestions would be very appreciated.
thx.
0 comments:
Post a Comment