Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

System.NullReferenceException: Object reference not set to an instance

Status
Not open for further replies.

Nesscafe

Programmer
Aug 1, 2006
19
RO
hi.. i have a small problem then i cant figure out. i have 2 sitemaps providers ( one for english and one for another language ). the files from english stay in "en" and the romanian language in "ro". i have 2 site.master pages. in the romanian page i put a button with the following code:

protected void Button1_Click(object sender, EventArgs e)
{
string url;
url = SiteMap.CurrentNode.Url.Replace(ResolveUrl("~/ro"), "~/en");
Response.Redirect(url);

}
so when i press the button it switches to the english files. my problem is with the button from the english page witch gives me an error. code for the english button:

protected void LinkButton1_Click(object sender, EventArgs e)
{
string url;
url = SiteMap.CurrentNode.Url.Replace(ResolveUrl("~/en/"), "~/ro/");
Response.Redirect(url);
}

so the problem is that it gives me this error :
" System.NullReferenceException: Object reference not set to an instance of an object "

Stack Trace:


[NullReferenceException: Object reference not set to an instance of an object.]
Site.LinkButton1_Click(Object sender, EventArgs e) in c:\Documents and Settings\Taz\My Documents\Visual Studio 2005\WebSites\test-mnir\Site2.master.cs:33
System.Web.UI.WebControls.LinkButton.OnClick(EventArgs e) +105
System.Web.UI.WebControls.LinkButton.RaisePostBackEvent(String eventArgument) +107
System.Web.UI.WebControls.LinkButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +7
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +11
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +174
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +5102


anyone has any clue to solution? thx for the help


 
From VS Help said:
The SiteMap class retrieves the CurrentNode property by requesting it from the provider.

If no representative node exists for the page in the site map information, or if security trimming is enabled and the node cannot be returned for the current user, a null reference (Nothing in Visual Basic) is returned.
[/quote From VS Help]

Trace through your code, you are not finding the current node.
 
ok..but what if security trimming is off. and why does the same code work for 1 button but not for the second one, even if it's only reversing the url that needs to be replaced.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top