What is wrong with this code ?

    protected void Page_Load(object sender, EventArgs e)
        if (HttpContext.Current.User.IsInRole("MODERATOR"))
               BulletedList bl = (BulletedList)lvAdministrator.FindControl("bl");

<%@ Page Language="C#" MasterPageFile="~/SelfService/MpSelfservice.master" AutoEventWireup="true" CodeFile="Admin.aspx.cs" Inherits="Admin" Title="Untitled Page" %>

<asp:Content ID="Content1" ContentPlaceHolderID="cphBody" Runat="Server">
    <asp:LoginView runat="server" ID="lvAdministrator">
    <asp:BulletedList ID="bl" runat="server"><asp:ListItem>test</asp:ListItem></asp:BulletedList>


I always get this error : Object reference not set to an instance of an object.

is it possible there goes something wrong because I have nested masterpages ?

Kind Regards,

Joeri Pansaerts.

From Bruges, Belgium :)
6/22/2008 7:27:02 AM
asp.net.security 27051 articles. 1 followers. Follow

3 Replies

Similar Articles

[PageSpeed] 7

If you are using Membership and Roles provider, better to use:


Maybe if you want to do what you have above you should check if authenticated first

If (...User.IsAuthenticated)

  if ...

Peter Kellner
http://73rdstreet.com and blogging at
6/22/2008 3:06:30 PM

Thank you for your tip pkellner.

The problem comes from my nested masterpages ... for some reason (that I don't understand) I can't access the controls on a page (if the page has a nested masterpage).

An example :

I have in Default.aspx this control :

<asp:Literal ID="lt" runat="server" />

If I go to my Default.aspx.cs file, and I type :    lt.Text = "hallo";

I get the same error.

So for some reason there is a big problem if you work with nested masterpages. It's like the codefile don't see the aspx page in runtime ....

Kind Regards,

Joeri Pansaerts.

From Bruges, Belgium :)
6/22/2008 3:15:43 PM


Because you used the nested masterpage, so if you want to find the control of parent masterpage, you should use the id of the control.

for example:

Label lbl = (Label)Master.Master.FindControl("lblParentMaster");

But if you want to find the control of child masterpage , you sould use the name of the control at the runtime,

for example :

Button btn = (Button)Master.FindControl("ctl00$ctl00$ParentContentPlaceHolder$btnChildMaster");

Best Regards
XiaoYong Dai
Microsoft Online Community Support

Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
6/24/2008 6:46:00 AM

Similar Artilces:

.Net Framework Code Access Security
I built a c# .Net 2.0 based user control that I run as an ActiveX control in IE7.  It works fine except for code access security issues ("Request for the permission of type 'System.Security.Permissions.EnvironmentPermission, mscorlib, Version=, ......' failed).  To get around the code access security issues, I created a code group within the Machine All_Code group with the Publisher membership conditions based on a valid certificate (which my assembly has) and granted that code group the "Everything" permission set.  Even though my code group is m...

Securing .NET code
When you write your code, compile it, and distribute the exe/dll's, is your source safe? We're not talking about protection against buffer overruns, SQL injection and various other code hacking techniques, we're talking protection of the source code itself, protection of intellectual properties.This article is the result of me touring the danish universities as a Microsoft Student Partner, giving lectures on the subject of securing code and intellectual properties in the realm of the .NET Framework.http://www.improve.dk/articles/dotnet/securing-dotnet-code/Let me know what you th...

Translate c#.net code to vb.net code
Hi I can usually do the translation myself, but this time I am a bit stumped  Let us consider to rewrite Urls (more than 16000 links) using a table. Save original url and rewritten url in a table. Now add a class file in App_Code folder. class UrlRewriteModule : IHttpModule{    public void Dispose()    {        // Nothing to dispose    }    public void Init(HttpApplication context)    {        context.BeginRequest += new EventHandler(context...

How to convert C#.Net code to VB.Net code ???...
HI, i was searching something new, then i suddenly find some tips to convert C#.Net code to VB.Net but i did not do well. i am puttint its url here plz tell me how to convert C#.Net code to VB.Net. http://www.dotnetspider.com/code/C-273-Convert-C-VB-NET.aspx Jasim...Please remember to click “Mark as Answer” on the post that helps youJasim AkhtarNew Delhi ( INDIA ) It would be better if you write the problem you having, while converting from C# to VB.NET. You cannot completely rely on online converters. ThanksMark post(s) as "Answer" that helped youElectronic ScrewWebsite||Bl...

.Net code access security has no effect.
Hi All. I have built a library -MyLib.dll -  for my asp.net application that has been signed using public-private keypair made from sn.exe. I signed it from the signing option in visual studio 2005 and gave the public-private key pair file. I had already added  the StrongNameIdentityPermissionAttribute to one of my classes inside Mylib.dll like the follwowing namespace Test { public class Sample { [StrongNameIdentityPermission(SecurityAction.Demand, PublicKey = "...")] public static void SayHello() { System.Diagnostics.Debug.Writ...

what is the use of code access security in .net
Hi,   what is the use of code access security in .net, and how to work in .net 3.5 If you have your code running in separate assemblies then you can restrict the permission set for that assembly by using CAS.You could restrict a desktop application from making DNS requests for example. This section of msdn is devoted to explaining the concepts and usage of Code Access Security:http://msdn.microsoft.com/en-us/library/930b76w0.aspx Hi good example of CAS is Microsoft SharePoint (WSS 3.0). While Creating your own web parts for sharepoint you will required CAS for your WebPa...

Name: ROZ mandelcorn Email: thunderstaratearthlinkdotnet Product: Firefox Summary: WRONG WRONG WRONG Comments: as a long-time user, first of netscape and, mozilla firefox, i must say i DO NOT LIKE THE PLACEMENT of TABS in version 4. nor do i like the whole rearrangement of the upper/navigation portion of firefox. I NEED/WANT MY TABS DIRECTLY ABOVE MY WINDOWS AS IT IS NOW....NOT ON TOP OF THE BROWSER. I WANT MY FILE-EDIT-ETC-MENU on TOP. ETC. AT LEAST GIVE US THE CHOICE AS TO WHICH FORMAT WE WANT....CAN YOU SAY CUSTOMIZATION! I WILL NOT USE 4 IF THIS IS THE WAY IT IS. [just ...

What's wrong in my VB.NET code?
Dear all, I'm trying to write the code for a "login" button, to check if the username & password is correct or not and if it's correct check the type, because I have 3 types of users, and each case there should be an update but it's not updating, please check my code below and tell me what's wrong? why it's not updating in the database? I'm using ASP.NET 2003 and SQL 2000.Private Sub login_btn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles login_btn.Click CheckAccess() End Sub  Private Sub CheckAccess() Dim type A...

How to develop .NET security code as a non-admin
The trick to developing code in a nonprivileged environment is to have your main interactive logon be nonprivileged but to keep an admin logon in your pocket for those times that you need it. Look, it doesn't take administrative privileges to edit a text file, and that's what you're doing most of the time when you're programming, right? And you don't want your programs to require admin privileges to run, which is the point of this whole exercise. So your main logon, where you write, compile, link, and test your code (and where you surf the Internet, of course) should...

Code generation in Microsoft.net ( code that writes code ) Whats its future
Hello, I was just reading a book about Code Generation in .NET. Its damn hard book to read. What do u think is the future of Code GenerationHighOnCodingWanna get high! It's being used now quite a bit. Not necessarily out the box click a button, and you get an application, but applications will generate specific code to function dynamically.Kay LeeMySpace.com - http://www.myspace.com/kragieInfrastructure GroupMySpace.com- Code to live, but Live to code. the refactoring tools already available (and those that are destined for the new IDE) use the same techniques. we will pr...

use VB.NET and C#.NET code in the same C#.NET project
All-- Here is a sample that is "off the beaten path", (at least for me). Is it possible, in an ASP.NET application, using the code-behind page building technique, to have both pages written in VB.NET and pages written C#.NET?At http://www.WebLogicArts.com/DemoList.aspx there is a sample that shows that, (contrary to popular belief), it IS possible to mix ASP.NET pages built with C#.NET with ASP.NET pages built with VB.NET in the same VS.NET 2003 project. Note that this is just a "fun" sample to see if it can be done and I do not recommend this practice as a "standard" way of develo...

Looking for good .NET Code Access Security links
I have been reading several of the Microsoft Code Access Security documents. I was look for good links addition sites (user sites, blog site, etc.) where developers are actively implementing Code Access Security (CAS). Thanks for any feedback. Mark Wagner Simple Thoughts from a Simple Mind Blog: http://blogs.crsw.com/mark...

Re: NET::LDAP with Unicode to prevent wrong ASN1-Coding
> Date: Fri, 2 May 2003 14:23:40 +0100 > From: Graham Barr <gbarr@pobox.com> > Convert::ASN1 does not care about character sets at all. And it should > not attempt to convert between them. In this respect if Convert::ASN1 > is passed a string witht the utf8 fllag set then I think its duty > is to pass the "bytes" it was passed. OK, you are right. It ist not task of the ASN-structuring to deal with character sets. But then it is task of the Net::LDAP-package to accept a string-parameter with or without the perl-utf8-bit set. (And code all string...

Re: NET::LDAP with Unicode to prevent wrong ASN1-Coding #2
> Date: Fri, 2 May 2003 18:44:48 +0100 > From: Graham Barr <gbarr@pobox.com> > Subject: Re: NET::LDAP with Unicode to prevent wrong ASN1-Coding > I agree. And I think adding the following into Convert/ASN1/_encode.pm > will solve it > > use constant CHECK_UTF8 => $] > 5.007; > > if (CHECK_UTF8) { > require Encode; > require utf8; > } > > And change _enc_string to > > sub _enc_string { > # 0 1 2 3 4 5 6 > # $optn, $op, $stash, $var, $buf, $loop, $path > > if (CHECK_...

Making Wrong Code Type Wrong
--4OpS+d6oOtUQaRm1 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable JoelOnSoftware wrote an article I recently saw linked on perlmonks: http://www.joelonsoftware.com/articles/Wrong.html The article discusses writing robust software, specifically by dealing with data separation. In my interpretation the article introduces a type system. This type system helps write robust software, but has some limitations: * Type information is checked by the programmer * Full annotations must be supplied by the programme...

Web resources about - What is wrong with this code ? - asp.net.security

Wrong - Wikipedia, the free encyclopedia
while civil law countries tend to have some additional categories, such as contraventions . Moral wrong is an underlying concept for legal wrong, ...

The Wrong Path? Facebook Cuts Off Access To Find Friends API From Social Network’s App
Social network Path became the latest application to lose access to Facebook’s find friends application-programming interface, prohibiting Path ...

To the National Review Online: This Wrong Needs to be Righted! - Facebook
Allen West hat eine Notiz mit dem Titel To the National Review Online: This Wrong Needs to be Righted! geschrieben. Du kannst den vollständigen ...

Why you may be learning the wrong reasons from Facebook marketing gurus
... ROI of over 1,200%. As had been noticed, even little engagement, social media can be used to directly generate sales. But don’t get me wrong, ...

Hong Wrong Blog (@hongwrongblog) on Twitter
Sign in Sign up To bring you Twitter, we and our partners use cookies on our and other websites. Cookies help personalize Twitter content, tailor ...

Scripting News: Silicon Valley is wrong about college.
Lately I've been thinking a lot about startup culture, and am reminded of its nobility having started three companies in my career, and learned ...

Scripting News: Why Charles Pierce is wrong about Ezra Klein being wrong.
... Pierce's attitude many times, from all kinds of ink-stained pros, some very accomplished. The arrogance is impressive, but they're still wrong. ...

Scripting News: I had to get a NYT Digital Subscription to figure out what's wrong.
Yesterday I posted a tweet with some feedback for the NY Times marketers. Getting a NYT Digital Subscription should open up something new and ...

Scripting News: Privacy is the sometimes wrong word.
You can talk about the security of your personal information in a different ways, each of which suggests a different set of issues. If I call ...

I Love You, David Byrne, But You're Wrong
David Byrne says he’s going to leave New York if the 1% succeeds in squeezing the creativity out of NYC. I have a different perspective. Maybe ...

Resources last updated: 1/18/2016 1:21:59 PM